<?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>command line arguments Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/command-line-arguments/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/command-line-arguments/</link>
	<description></description>
	<lastBuildDate>Sun, 14 Sep 2025 23:46:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>command line arguments Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/command-line-arguments/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>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>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>Thanks for watching!</p>



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p>Hello there. In this video,</p>



<p>I&#8217;m going to talk to you about how to accept incoming command line arguments to</p>



<p>an x86-64 Yasm assembly program that is probably linking to</p>



<p>GCC and is thus probably a hybrid program under the hood.</p>



<p>If you don&#8217;t know how to program in Yasm assembly yet,</p>



<p>check out my other videos. If you don&#8217;t understand command line arguments yet,</p>



<p>yet check my other videos I&#8217;m going to assume a lot of knowledge here I&#8217;m</p>



<p>really just going to show you how to pull the arguments inside of assembly</p>



<p>using using the GCC setup that they&#8217;ve given you so just a quick just a very</p>



<p>quick recap this is not a command line arguments video if we have the program</p>



<p>echo and we give it like one argument of just the word hello then it&#8217;s it&#8217;s</p>



<p>going to receive one command line argument in addition to its program</p>



<p>echo as argument zero and hello as argument index one.</p>



<p>And it&#8217;s just going to be able to look at them and say,</p>



<p>oh, the user wants me to print this hello string.</p>



<p>So it just prints it.</p>



<p>And so that&#8217;s kind of how you can tell a program what to do,</p>



<p>either when you&#8217;re running them directly</p>



<p>or having one program automate another program.</p>



<p>Anyway, so in our Yasm assembly programs,</p>



<p>how do we actually get that out?</p>



<p>Well, for starters, we are dynamically linking.</p>



<p>Sorry, not dynamically linking.</p>



<p>We are linking a hybrid program.</p>



<p>So I just want to make sure that you understand this is the right video for you.</p>



<p>If you&#8217;re trying to do this in pure assembly, or if you need to know that for some reason,</p>



<p>then you&#8217;ll probably want to watch the next video that I publish.</p>



<p>But for now, this is a hybrid program.</p>



<p>Hybrid programs, for those of you who don&#8217;t know, it just means you have modules that</p>



<p>are written in different source code and they&#8217;re compiled differently, different source code</p>



<p>languages.</p>



<p>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>And you compile them all down to their own object files and then you link them together into an executable</p>



<p>If GCC is part of the linking process</p>



<p>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>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>So if you don&#8217;t understand it go look at my other videos</p>



<p>But basically I&#8217;m just going to assemble with Yasm and I&#8217;m going to use G++ as the linker</p>



<p>and I&#8217;m going to gobble up all of the object files. Here&#8217;s like a little menu.</p>



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



<p>is not really a hybrid program. This is just kind of a pure assembly program that is linked with GCC,</p>



<p>but you can imagine you could add other source files in C and C++ and still totally get away</p>



<p>GCC. But anyway, I&#8217;m just compiling one source code of assembly and,</p>



<p>and compiling it down to an object file right here.</p>



<p>And then when it comes time to linking, uh, you can kind of tell here, uh,</p>



<p>especially if you&#8217;re familiar with make files that I&#8217;m just gobbling up all the</p>



<p>object files and linking them together into the executable.</p>



<p>So that&#8217;s as far as I&#8217;ll go there again,</p>



<p>I&#8217;ve got another video that totally explains a lot more in my assembly program.</p>



<p>video just for pure assembly so if you don&#8217;t understand assembly see my other videos but for</p>



<p>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>got a hello message a begin message a goodbye message carriage return line feed string i&#8217;ve</p>



<p>got the system call codes for you know printing to standard output and to exit the program and then</p>



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



<p>other videos. So because I&#8217;m linking with GCC, my text section here, the actual place where the</p>



<p>instructions are, not the data, is going to have a main entry point. So of course, if you had a</p>



<p>hybrid program, you could have main somewhere else in a different module and then just call on a</p>



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



<p>say this is the only source code file. So I mark main as global and I put main right here. And then</p>



<p>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>And then I return a return value.</p>



<p>Standard assembly stuff covered in other videos.</p>



<p>But here&#8217;s the key for getting command line arguments in assembly.</p>



<p>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>register or rather I should say the first integer argument I haven&#8217;t talked</p>



<p>about to float arguments in any of my videos yet in the future you should</p>



<p>probably search for other videos that that explain how to do float arguments</p>



<p>but for now all of the arguments I&#8217;m talking about in this video are just</p>



<p>integer arguments and pointer arguments which is kind of the same thing a</p>



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



<p>using it as an integer so anyway first argument comes in on RDI second argument</p>



<p>comes in on RSI and you can imagine that basically this is the thing you&#8217;re</p>



<p>probably used to seeing in your C++ programs if we do this int main and then</p>



<p>integer arg C and then a character pointer arg V and then an array those are</p>



<p>those two registers right there I probably want to change this into long</p>



<p>because you know rdi is in 64-bit form but an integer is an unsigned 32-bit int.</p>



<p>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>care. Anyway so we&#8217;re just going to grab those two things so obviously rdi is probably pretty</p>



<p>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>to use it to control a loop counter that&#8217;s going to loop through all incoming arguments.</p>



<p>which is going to be the name of the program in this case it&#8217;ll be I think</p>



<p>just main is what I called it which is confusing against the entry point I</p>



<p>admit it but imagine that my main program that sits in the file system is</p>



<p>actually called program or hello or whatever so that&#8217;s the number of</p>



<p>arguments in RDI and then RSI notice how it&#8217;s a character pointer to an array of</p>



<p>characters that means it&#8217;s actually a pointer to a pointer and the reason for</p>



<p>every argument on the command line like for instance if i went back here and i said echo</p>



<p>hello let&#8217;s just do without quotes hello you i&#8217;ve given it two arguments and so when the program</p>



<p>launches it&#8217;s going to receive three total it&#8217;s going to receive its own program name at index zero</p>



<p>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>two the second argument as you it prints them both so how does echo know how many arguments i have</p>



<p>strings. Remember argc is the number of arguments so that&#8217;s kind of easy but how does it dereference</p>



<p>all of the strings if there could be any number of strings? Well that&#8217;s this right here.</p>



<p>This whole symbol argv is a pointer and it points to an array of pointers, of character</p>



<p>pointers. That&#8217;s why it&#8217;s written like this like an array. So it&#8217;s a pointer that points</p>



<p>points to an array.</p>



<p>So like if you go to that location in memory,</p>



<p>then what you will see there for the first eight bytes</p>



<p>is just the address of some other memory location where a string has been stored.</p>



<p>Then if you advance that pointer another eight bytes for it,</p>



<p>you know, in memory, because all pointers are eight bytes or 64 bits,</p>



<p>then again, you&#8217;ll see that that value of that next eight bytes</p>



<p>is actually a memory location that points to another string somewhere else.</p>



<p>So these strings could be all over the place,</p>



<p>But the pointers to those strings are contiguous in memory starting with what you were given in RSI.</p>



<p>So it&#8217;s a character pointer pointer or an array of character pointers, however you want to imagine that.</p>



<p>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>For starters, I&#8217;m calling on an intro function which just basically prints some stuff.</p>



<p>I have a custom function that I wrote called print null terminated string.</p>



<p>That&#8217;s not the point of this video.</p>



<p>I have that explained in other videos a little bit.</p>



<p>So it&#8217;s up to you if you want to even care.</p>



<p>Right now I just want to be able to print something.</p>



<p>And then let&#8217;s see.</p>



<p>So after we print our welcome message in the intro, then we print another message basically</p>



<p>saying okay now we&#8217;re about to start printing all the arguments.</p>



<p>Okay cool.</p>



<p>Nothing complicated at this point.</p>



<p>Then I have another label here with my preferred style of adding a suffix after the function</p>



<p>after the function that I&#8217;m currently inside of.</p>



<p>And I&#8217;m going to say, all right, this is where I initialize my loop.</p>



<p>This is not a looping video, so I&#8217;m going to skim through it kind of.</p>



<p>But I&#8217;m basically going to say, let&#8217;s start the loop as basically saying</p>



<p>the index of the argument that we&#8217;re currently looking at is zero</p>



<p>because we&#8217;ll start with zero.</p>



<p>So that means we&#8217;ll print like if we were going to, if our program was named Echo,</p>



<p>we would also print Echo itself and not just all the incoming arguments</p>



<p>that the user might have typed.</p>



<p>index zero and then we&#8217;re going to use r15 as the current character pointer so r15 its current</p>



<p>character pointer is going to be coming from r13 which was the argv argument so that means</p>



<p>r15 is now going to hold a pointer uh let&#8217;s see it&#8217;s going to hold</p>



<p>when you have an array and the array is contiguous in memory then the pointer itself that points to</p>



<p>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>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>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>go off to a null terminated string i know that sounds weird you got to get used to double dereferencing</p>



<p>here so all we really need to do to access uh the first pointer to the actual string is take the</p>



<p>array pointer that we have and dereference it one time so remember we&#8217;re receiving an argv</p>



<p>a pointer to a pointer or like a you know a double pointer if we dereference it once then we should</p>



<p>terminated string. Anyway, so that&#8217;s the initialization part. I&#8217;m going to start looking</p>



<p>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>my loop. You can imagine this is a while loop. This is not a while video, but you know, there it is.</p>



<p>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>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>the number of arguments so notice how like right here we grabbed RDI right</p>



<p>into R12 right away so basically I&#8217;m saying if the index we&#8217;re currently</p>



<p>looking at is greater than or equal to the number of arguments then we&#8217;re</p>



<p>actually already done remember if we&#8217;re using zero based indexing and you</p>



<p>suppose that you have three items in your array their indexes would be zero</p>



<p>So that means if the size of your array is three, like the count, like the RFC, that</p>



<p>means the last valid index is two.</p>



<p>It&#8217;s one less than the size.</p>



<p>You know, it&#8217;s one less than the count.</p>



<p>So I&#8217;m saying at this point that if we ever reach an index number that is equal to the</p>



<p>size, then we&#8217;ve already finished.</p>



<p>We do not need to look at the current item.</p>



<p>So I&#8217;m comparing those two registers.</p>



<p>You know, where are we looking at versus what is the count?</p>



<p>You know, what is the index we&#8217;re looking at versus the count?</p>



<p>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>I&#8217;m going to jump out of the loop to a label called main loop done.</p>



<p>So then, you know, that&#8217;s down here.</p>



<p>Basically, we just say goodbye and then we jump to our exit function.</p>



<p>And all that does is it just returns from main with some kind of a success code.</p>



<p>You know, so just you can imagine in C++, it&#8217;s just return zero.</p>



<p>So, you know, breaking the loop doesn&#8217;t really do anything except end the program and say goodbye.</p>



<p>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>we did jump, we compared it, we realized that we&#8217;re done.</p>



<p>Then it&#8217;s going to jump down to the, to the done.</p>



<p>But if we&#8217;re not done, execution is going to fall through to the next statement.</p>



<p>So that means we&#8217;re going to end up doing something with the current item inside of</p>



<p>our loop.</p>



<p>So what are we going to do?</p>



<p>We&#8217;re going to dereference R15.</p>



<p>was your pointer to a pointer it was your double pointer there if we dereference it once then</p>



<p>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>character that starts one string so dereferencing it once means you know i put brackets around the</p>



<p>double pointer it&#8217;s now dereferenced once that means rdi is going to receive a pointer to one</p>



<p>into my function my function takes two arguments it wants a pointer to a string and it wants</p>



<p>the file descriptor to print to again other videos explain you know printing to standard</p>



<p>output but i&#8217;m just going to print the string so this part right here should actually print</p>



<p>the argument and then after we&#8217;re done with that uh well maybe i should change this</p>



<p>so that it&#8217;s a little bit more clear i&#8217;m going to maybe push this down and say</p>



<p>these lines up here actually do something they do the printing by</p>



<p>dereferencing and then here we just sort of increment along the array of pointers</p>



<p>and jump back to the top of the loop so what are we doing here with r14</p>



<p>remember r14 was the index that we&#8217;re currently looking at so we we start</p>



<p>looking at index 0 line 83 is going to say let&#8217;s next look at index 1 and then</p>



<p>this part right here add 8 to r15 that just basically means remember r15 was</p>



<p>remember r15 was the double pointer the double pointer like i said before it&#8217;s looking at an</p>



<p>array of pointers so it&#8217;s actually a pointer to a pointer if i increase the memory location that</p>



<p>r15 holds then it&#8217;s now looking at the next pointer it&#8217;s moving through the array r15 at</p>



<p>that point would no longer be a valid pointer to the original array it&#8217;s sort of like a running</p>



<p>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>a pointer is eight bytes so if we&#8217;re just looking at the first pointer and we increase the memory</p>



<p>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>next iteration of the loop if we dereference then we&#8217;re going to end up dereferencing to the second</p>



<p>string then i just print a little new line here honestly probably should have put that up top</p>



<p>sloppy code i was doing this quickly and then we jump to the top of the loop so then we just</p>



<p>going up to the top of the loop and printing arguments and advancing to the</p>



<p>next pointer. And we just keep going at it.</p>



<p>Let me see if this works. Hopefully I didn&#8217;t mess this up while I was screwing</p>



<p>around. All right. So I&#8217;m going to do this make run. Okay.</p>



<p>So under the hood inside of my make file,</p>



<p>maybe let&#8217;s open the make file real fast just so you can see.</p>



<p>I&#8217;m just going to nano it real fast here under the hood.</p>



<p>So when I call the program to run, notice how I&#8217;m giving it arguments.</p>



<p>You can see right here on this line, or actually let me get the line numbers up.</p>



<p>You can see on line 48, I am calling my executable, which is named main.</p>



<p>In the make file, I&#8217;m using a variable, so don&#8217;t worry about that.</p>



<p>But I&#8217;m giving it four arguments.</p>



<p>And I&#8217;m just saying first arg, second arg, third arg, fourth arg.</p>



<p>So that&#8217;s why you see that printed in the previous screen.</p>



<p>screen it&#8217;s just going through all the arguments that I gave it it&#8217;s saying</p>



<p>first arg second arg third arg fourth arg notice how it knows when to stop</p>



<p>because of the argc that came in on RDI now that the program is built you know</p>



<p>I&#8217;ve got my main executable which I named main which I said before was kind</p>



<p>of confusing now that I&#8217;ve got it I can just execute it again and give it like</p>



<p>one argument of like hello notice how it prints hello on a line by itself you do</p>



<p>do it again dudes and notice how every argument I give it it just prints it no</p>



<p>matter how many I do I can go a b c d e f g I could probably do this so many</p>



<p>times that I exhaust you know a long integer which is would be a horrible</p>



<p>endeavor but yeah everything that I put on there it just loops through it and</p>



<p>prints it so when you are linking with GCC because you&#8217;re probably using a</p>



<p>if you&#8217;re just linking with GCC.</p>



<p>GCC makes it really, really easy</p>



<p>to access the command line arguments.</p>



<p>Imagine now instead of just printing these things,</p>



<p>you used them to somehow decide</p>



<p>what your program was gonna do.</p>



<p>Maybe the user will give you a sub command.</p>



<p>Like if you&#8217;re a Git user, we say Git status, right?</p>



<p>So the Git says like, oh, you Git launches</p>



<p>and it goes, you want the status of something?</p>



<p>Yeah, sure.</p>



<p>So in your program now,</p>



<p>you could read what the user typed,</p>



<p>figure out a way to parse it and interpret it</p>



<p>have your program&#8217;s behavior adjust to whatever the user typed in okay that&#8217;s it for this video</p>



<p>the next video I&#8217;m going to post is how to do basically exactly the same thing but using pure</p>



<p>assembly without linking against GCC so like LD is going to be the linker just like pure assembly</p>



<p>no extra libraries okay thank you so much for watching this video I hope you learned a little</p>



<p>tell your friends and i&#8217;ll see you in the next video</p>



<p>hey everybody thanks for watching this video again from the bottom of my heart i really appreciate it</p>



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



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



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



<p>and grow this community so we&#8217;ll be able to do more videos, longer videos, better videos,</p>



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



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



<p>somebody subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s exactly</p>



<p>what happens every single time. So you could do it as a nice favor to me or you could troll me if</p>



<p>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>just wake up I promise that&#8217;s what will happen also if you look at the middle of</p>



<p>the screen right now you should see a QR code which you can scan in order to go</p>



<p>to the website which I think is also named somewhere at the bottom of this</p>



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



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



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



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



<p>say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever i also wake up for</p>



<p>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>really mean the world to me i would really appreciate it so again thank you so much for</p>



<p>watching this video and um enjoy the cool music as as i fade into the darkness which is coming for us</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/">Command Line Arguments in Yasm Assembly with GCC: A Practical Guide</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/command-line-arguments-in-yasm-assembly-with-gcc-a-practical-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Command Line Arguments in x86-64 Assembly with YASM</title>
		<link>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/</link>
					<comments>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 08 Sep 2025 07:44:41 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[argc argv]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[command line arguments]]></category>
		<category><![CDATA[Linux programming]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[stack pointer]]></category>
		<category><![CDATA[system calls]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=221</guid>

					<description><![CDATA[<p>Learn to access command line arguments in x86-64 YASM assembly on Linux. Master stack handling and argv looping in this clear, practical tutorial!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/">Master Command Line Arguments in x86-64 Assembly with YASM</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 Command Line Arguments in x86-64 Assembly with YASM" width="1380" height="776" src="https://www.youtube.com/embed/hRl3hKvHiyM?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>Want to master command line arguments in pure x86-64 YASM assembly on Linux? This video breaks down how to access argc and argv directly from the stack, without GCC libraries. Follow along as we write a program to loop through and print user-provided arguments, complete with a visual stack explanation. Whether you&#8217;re new to assembly or leveling up, this tutorial offers clear, practical insights for coding low-level programs. Check out my other videos for more assembly tips, and subscribe for more coding goodness!</p>



<p>Introduction to Command Line Arguments 00:00:00<br>Target Architecture and Assumptions 00:00:04<br>Recap of Command Line Arguments 00:00:56<br>Accessing Arguments in Pure Assembly 00:01:47<br>Program Structure and Data Section 00:02:19<br>Stack Pointer and Argument Count 00:04:16<br>Accessing Argument Vector (argv) 00:07:14<br>Looping Through Arguments 00:12:16<br>Incrementing to Next Argument 00:16:45<br>Visualizing the Stack 00:19:24<br>Running the Program with Arguments 00:21:56<br>Conclusion and Call to Subscribe 00:23:48</p>



<p>Thanks for watching!</p>



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



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



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



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



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



<li>Subscribing to our Blog</li>



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



<p>hey there let&#8217;s talk about accepting command line arguments in a pure assembly program</p>



<p>written for x86-64 aka amd yasm assembly</p>



<p>on linux anyway so uh there are going to be a lot of topics that i that i sort of mention in this</p>



<p>video that are not actually covered in this video so if you feel yourself getting lost like for</p>



<p>program in assembly in the first place.</p>



<p>If you don&#8217;t know what command line arguments are,</p>



<p>if you don&#8217;t know the terminal, things like that,</p>



<p>you probably want to check out my previous videos</p>



<p>because they will be explained in detail.</p>



<p>For now, I&#8217;m just going to assume you know how to do all this basic stuff.</p>



<p>And the only thing that I need to show you</p>



<p>is how to write a program in Yasm assembly that can</p>



<p>grab your command line arguments.</p>



<p>So, you know, just to do a quick recap of what I&#8217;m even talking about.</p>



<p>echo we can launch it with no arguments it doesn&#8217;t do anything but we can give</p>



<p>it some arguments we can say hello and then we can say goodbye and that&#8217;s two</p>



<p>arguments that I&#8217;m giving to echo echo will grab on to the arguments it was</p>



<p>given it&#8217;s actually going to receive three arguments the index zero argument</p>



<p>being the name of itself its own program and then the next two arguments being</p>



<p>the stuff that I typed after the program but you can see that it somehow figured</p>



<p>two arguments as strings and print them right so imagine you have an assembly</p>



<p>program and you want the user to be able to launch your program and add</p>



<p>arguments at the end of the command line and have your program behave in some</p>



<p>certain way according to what the user wants the question then becomes how do</p>



<p>you access those arguments it&#8217;s a little bit easier in GCC look at my other video</p>



<p>that I posted about the topic for GCC linked assembly programs it&#8217;s a little</p>



<p>You pretty much just look at RDI and RSI to get your argc and your character pointer array.</p>



<p>When you&#8217;re dealing with pure assembly though, the GCC libraries don&#8217;t bundle up the command</p>



<p>line arguments in a really convenient way for you.</p>



<p>You&#8217;ve got to look for them elsewhere.</p>



<p>It&#8217;s honestly not that much harder.</p>



<p>It&#8217;s just a little, feels a little weird.</p>



<p>I think at least for me, I was hoping to see the arguments in a register and I did not.</p>



<p>But anyway, so here&#8217;s my program.</p>



<p>Again, this is not an assembly programming video.</p>



<p>an assembly programming video if you need to know how to program assembly see my other videos for</p>



<p>now i&#8217;m just going to quickly go over it i&#8217;ve got my data section in yasm i am printing out a couple</p>



<p>of strings or i i have a couple of strings defined i&#8217;m saying like the module has started i&#8217;m going</p>



<p>to begin printing arguments i have some system call codes so that i can write just to standard</p>



<p>output and so that i can exit the program this is pure assembly so we don&#8217;t actually return from</p>



<p>we just get jumped into and then we call exit normally and then here&#8217;s the standard output pipe</p>



<p>again another video covers that and then i&#8217;ve got the exit success code again another video covers</p>



<p>that but basically you know exiting zero is usually what you do for success then i&#8217;ve got the</p>



<p>text section which holds all my assembly instructions and this is my entry point we don&#8217;t</p>



<p>really need to uh push and pop these registers because we&#8217;re just going to exit the program when</p>



<p>it&#8217;s totally fine we would need to preserve Kali saved registers if we were</p>



<p>jumping into a main function or if this was a different function that was being</p>



<p>jumped into but we&#8217;re not so we don&#8217;t have to anyway here&#8217;s my entry point the</p>



<p>underscore start for a pure assembly program and then I&#8217;m going to grab the</p>



<p>incoming arguments when you&#8217;re linking with GCC which we&#8217;re not doing here in</p>



<p>this video then the arguments come in very easily they just come in argc</p>



<p>up in RDI and arg sorry argc comes into RDI and the character pointer array comes in as RSI so you</p>



<p>can imagine in GCC this would be integer main and then integer argc character pointer array argv</p>



<p>right hopefully you&#8217;ve done this in a higher level language so you have a better idea of what I&#8217;m</p>



<p>talking about if not I guess that&#8217;s okay it will still allow you to grab even if you don&#8217;t</p>



<p>it will still allow you to grab,</p>



<p>even if you don&#8217;t understand this in C++.</p>



<p>So argc is actually the stack pointer.</p>



<p>The stack pointer register, RSP,</p>



<p>always tells you where the top of the stack is,</p>



<p>like what&#8217;s the last piece of data</p>



<p>that we actually have sitting on the stack.</p>



<p>So that&#8217;s gonna be the count of arguments.</p>



<p>argc is always gonna be the stack pointer.</p>



<p>So if you dereference the stack pointer register,</p>



<p>pointer register then what you&#8217;re doing is you know the stack pointer register</p>



<p>actually points to memory locations within the stack so if the memory</p>



<p>location that it&#8217;s looking at is where argc is stored then you dereference it</p>



<p>with the brackets and you&#8217;ll actually get argc so right away I&#8217;m just gonna</p>



<p>steal argc off the top of the stack and this is a good idea to do right away</p>



<p>because if you start doing other stuff you might end up modifying the stack</p>



<p>especially if you start calling functions and things like that and and</p>



<p>and and these these pieces of information will be lost or they&#8217;ll be a lot harder to find so right</p>



<p>away i&#8217;m just going to say argc goes directly into r12 and i have a little comment reminder</p>



<p>for myself at the top saying r12 is now argc same thing for uh r13 i&#8217;m going to say that&#8217;s a pointer</p>



<p>to my character pointer array i talked about this in depth on my other video where we talked about</p>



<p>an assembly program but basically if you look at uh if you look at argv right here it&#8217;s not just a</p>



<p>pointer and it&#8217;s not just an array it&#8217;s a pointer to an array and if you recall in higher level</p>



<p>languages or just i guess anything an array itself is a pointer because argv the symbol let&#8217;s say we</p>



<p>were in a higher level language argv can only point to one thing so it&#8217;s going to point to the very</p>



<p>but the beginning of your array is not going to be one string like one argument that the user gave</p>



<p>you because the user could give you many arguments instead it&#8217;s an array of pointers</p>



<p>so it&#8217;s a character pointer array meaning argv is a pointer to a pointer</p>



<p>the first item in any array is what is pointed to by the symbol so like imagine if we had just</p>



<p>had just for the sake of argument imagine if we had an integer array let&#8217;s say we had like 500</p>



<p>integers in like a c++ program so the symbol a is what i&#8217;m trying to say the symbol a</p>



<p>is really a pointer that points to the first integer in that array and then later of course</p>



<p>you can dereference that pointer with some sort of an index to get the index 5 integer or the</p>



<p>the array and a pointer to the first item.</p>



<p>Or I guess you could say it&#8217;s both a pointer to the array</p>



<p>and a pointer to the first item,</p>



<p>because it&#8217;s kind of the same thing.</p>



<p>So that means if we grab argv,</p>



<p>then we&#8217;ll be grabbing a pointer.</p>



<p>If we then dereference that pointer,</p>



<p>it would tell us where another pointer is.</p>



<p>And then that other pointer would point to a string</p>



<p>representing the first argument.</p>



<p>first argument so we&#8217;ll explain that more as i do this loop i&#8217;m going to i&#8217;m going to show you</p>



<p>some code that actually loops through all the arguments anyway the thing about where to find</p>



<p>that argv is it&#8217;s just the next pointer or i guess it&#8217;s the it&#8217;s the next item that the stack holds</p>



<p>so remember i told you that rsp when this when this function comes in rsp is a pointer to wherever</p>



<p>we&#8217;re we&#8217;re looking what memory location the top of the stack is so if we dereference that we get</p>



<p>So if we dereference that, we get argc.</p>



<p>Well, we just need to go find the next previous item in the stack</p>



<p>and then dereference that so that we can get the first pointer or argv,</p>



<p>you know, the first pointer to a pointer,</p>



<p>or the first double pointer in your array of pointer to pointers.</p>



<p>Why am I doing plus eight?</p>



<p>This might actually make sense as is,</p>



<p>sense as is but it&#8217;s important to understand that when you add stuff to the stack you&#8217;re actually</p>



<p>decreasing the memory locations uh that you are pointing to so like if i if i increase a stack</p>



<p>this is not a stack video there&#8217;s other videos that i have for that um if we add something to</p>



<p>the top of a stack you imagine the stack growing visually in a in a vertical direction like it&#8217;s</p>



<p>growing up right but inside of the computer the memory locations are actually going down</p>



<p>If we&#8217;re looking at the stack pointer and we&#8217;re adding eight, what it&#8217;s saying is that</p>



<p>we&#8217;re looking back into memory that was already added for the stack.</p>



<p>So that&#8217;s like if we grew the stack, that would be subtracting from the memory location.</p>



<p>So like looking further up in the stack would be subtracting from the memory location because</p>



<p>the stack grows upward in the abstract, but downward in memory locations.</p>



<p>So that means if we add eight, that means we&#8217;re going in the other direction.</p>



<p>that means we&#8217;re going in the other direction.</p>



<p>We&#8217;re looking downward into the stack.</p>



<p>So what that means is that the top two items on the stack</p>



<p>are first argc and then second, that first pointer,</p>



<p>you know, the argv argument.</p>



<p>And that&#8217;s how we access it with plus eight.</p>



<p>Why is it a plus eight instead of plus something else?</p>



<p>Because all pointers on 64-bit systems are 64-bit integers</p>



<p>and 64-bit integers are eight bytes.</p>



<p>If we&#8217;re talking about eight bytes, sorry,</p>



<p>if we&#8217;re talking about eight bits per byte.</p>



<p>So this is just how you access it.</p>



<p>What about this other thing going on here?</p>



<p>What&#8217;s this LEA instruction?</p>



<p>Usually you see a move instruction, right?</p>



<p>So we basically want to look at the stack pointer,</p>



<p>but look one level lower.</p>



<p>And each item on the stack is also going to be eight bytes.</p>



<p>We want to look one item lower on the stack,</p>



<p>and then we want to dereference it.</p>



<p>but we don&#8217;t want to dereference and store the dereferenced value we still want to grab the</p>



<p>actual pointer the thing is I shouldn&#8217;t have said dereference in the first place these are dereferencing</p>



<p>brackets right so like up here on line 46 when you put brackets around rsp it dereferences whatever</p>



<p>value rsp holds so therefore when you put brackets around this you kind of expect that you&#8217;re going</p>



<p>to be dereferencing right but we don&#8217;t want to dereference we just want the original address that</p>



<p>showing us. So the problem with this is that when we say RSP plus eight,</p>



<p>we can&#8217;t actually do a mathematical formula unless we&#8217;re inside of brackets, which means we</p>



<p>can&#8217;t do them in a move instruction without accidentally dereferencing and losing a pointer</p>



<p>to the actual array of pointers. If we dereferenced like this, we would just end up with,</p>



<p>you know, a pointer to one string. So the way around this is instead of using the move instruction,</p>



<p>instead of using the move instruction we use the lea instruction the lea instruction allows us to</p>



<p>put a formula inside of brackets so that the assembler won&#8217;t get confused but then it won&#8217;t</p>



<p>put the dereferenced value into r13 it&#8217;ll just put the actual value of whatever we see</p>



<p>with that formula meaning it&#8217;ll give us the memory location of the item sitting one under the top of</p>



<p>this at this point r13 is now the memory location of the of the item sitting one underneath the top</p>



<p>of the stack and then we can de-reference that later in order to look at all of our arguments</p>



<p>so the next part of our code is just going to print an intro message so there&#8217;s like this intro</p>



<p>string up here hello and um i&#8217;m basically going to call a custom function that i made to just sort of</p>



<p>Printing. Don&#8217;t worry about this code right here.</p>



<p>This is not the point of the video.</p>



<p>I just made a custom function that just kind of helped me print.</p>



<p>Don&#8217;t worry about that.</p>



<p>The real meat of this video is that we&#8217;re going to loop through all arguments</p>



<p>and just print every single argument that the user provided.</p>



<p>So you can imagine this is maybe the top of a while loop here.</p>



<p>Notice how, oh, I forgot to replace main with start with start.</p>



<p>I had another version of this program that used main.</p>



<p>pretend we have this is called the main loop instead of the the main functions</p>



<p>loop anyway so main loop initialize first thing I&#8217;m going to do is I&#8217;m going</p>



<p>to initialize the loop by saying we&#8217;re looking at index 0 okay no problem so</p>



<p>we&#8217;re looking at index 0 we want to do that we want to look at all the</p>



<p>arguments you know we want to look at index 0 and index 1 and index 2 and we</p>



<p>just want to keep going until we&#8217;re out of arguments remember that we also have</p>



<p>the number of arguments coming from argc now sitting in r12. So that means if we have a</p>



<p>counter that starts at zero with r14 and then we know how many arguments there are in r12,</p>



<p>we should be able to know when the loop stops. So just a reminder that, you know, the loops here,</p>



<p>the arrays here are zero-based indexed or zero-index based, which means, for example,</p>



<p>that&#8217;s three arguments but the array of arguments is going to have indexes zero and one and two</p>



<p>which means the last valid index is going to be two or the size minus one think about that if you</p>



<p>have five arguments the last index that is valid is going to be four size minus one because it&#8217;s</p>



<p>zero based so we can use that logic to figure out if we&#8217;re done so we start off with an index of zero</p>



<p>here and then at the top of the loop i&#8217;m just going to quickly ask are we done how do we know</p>



<p>are we done how do we know if we&#8217;re done we compare the current index we&#8217;re</p>



<p>looking at with the count and we say if the current index we&#8217;re looking at is</p>



<p>greater than or equal to the count then we know we&#8217;re already done we don&#8217;t need</p>



<p>to look at any more indexes why am I saying is is the index greater than or</p>



<p>equal to the count because remember if we have five arguments then the last</p>



<p>valid index is four therefore if we find ourselves looking at index five we know</p>



<p>already done five is equal to or greater than five, but four is not equal to or greater</p>



<p>than five.</p>



<p>So that&#8217;s why I&#8217;m using this logic here.</p>



<p>I&#8217;m saying if we&#8217;re done, then jump to the done label.</p>



<p>Basically what&#8217;s the done label?</p>



<p>It&#8217;s main loop done.</p>



<p>All it really does is it says goodbye and then it just exits the program with a system</p>



<p>call.</p>



<p>Again, I have other videos that explain system calls and all that stuff.</p>



<p>So if we&#8217;re done, we, uh, we jumped down to the done area, but if not, then execute</p>



<p>to the done area but if not then execution will fall through to this next loop or sorry this next</p>



<p>label which is not necessarily we don&#8217;t really need a label there but i i like to put i like to</p>



<p>put it there just to help myself remember this is what it looks like in terms of a while loop you</p>



<p>know i have like here&#8217;s the top of the while loop here&#8217;s the little comparison part of the while loop</p>



<p>here&#8217;s the body like the opening braces of the while loop and then here&#8217;s sort of like the</p>



<p>closing braces i just like to do that but anyway after we decided that we are not done and we drop</p>



<p>done and we drop through to the next actual instruction we&#8217;re just going to</p>



<p>print the next argument so what&#8217;s the next argument we will dereference r13</p>



<p>remember up here we took the second item sitting like you know one under the top</p>



<p>of the stack and we just stuck it into r13 so this is r13 is now the address of</p>



<p>the second item on the stack if we de-reference it then that&#8217;s going to give</p>



<p>then that&#8217;s going to give us a pointer to our um sorry it&#8217;s going to give us a pointer to the first</p>



<p>item to the first string i should say to the first string uh the f this the string of the first</p>



<p>argument so if we dereference you know let me say this one more time just to make sure that i&#8217;m</p>



<p>item, you know, the item right under the top of the stack, that&#8217;s going to be a pointer</p>



<p>to the first argument string.</p>



<p>So if we just simply dereference R13, then we&#8217;re basically telling RDI, here&#8217;s a pointer</p>



<p>to the string that we want to print.</p>



<p>Okay, so then I just call my helper function to print that string to standard output, no</p>



<p>problem.</p>



<p>And then we have to figure out like, how do we increment to go to the next string?</p>



<p>might have been unclear earlier because gcc does it in a different way but on the stack</p>



<p>every item underneath the the top of the stack is a is another pointer it&#8217;s part of the original argv</p>



<p>array it&#8217;s another pointer to a different string so basically if i increase r14 here then i&#8217;m</p>



<p>increasing the index counter that&#8217;ll help us eventually terminate but notice how here i&#8217;m</p>



<p>Remember R13 is the second item, you know, the item right under the top of the stack.</p>



<p>And if I dereference that, then I now have a pointer to the first argument string.</p>



<p>If I want to go one lower into the stack, then I just add eight to that register&#8217;s value.</p>



<p>Because again, remember, the stack grows downward in memory.</p>



<p>So if I increase the value, then I&#8217;m sort of like going through previous items that were put into the stack.</p>



<p>So imagine the stack here, it&#8217;s got like,</p>



<p>you know, argc sitting on top</p>



<p>and then underneath argc,</p>



<p>it&#8217;s got a pointer to the first argument.</p>



<p>And then under that in the stack,</p>



<p>it&#8217;s got a pointer to the second argument.</p>



<p>And then under that in the stack,</p>



<p>it&#8217;s got a pointer to the third argument.</p>



<p>Then under that, it&#8217;s got a pointer</p>



<p>to the next argument and so forth.</p>



<p>So every time we wanna go to the next arguments pointer,</p>



<p>the next arguments string pointer,</p>



<p>we just add eight to that R13 register,</p>



<p>which was originally just pointing at the first string.</p>



<p>so again why eight because pointers are 64-bit integers therefore they are eight bytes so I&#8217;m</p>



<p>just literally increasing the index by one and then I&#8217;m moving that register r13 to point to</p>



<p>the next pointer that way next time I dereference it up here on line 70 I&#8217;ll be dereferencing the</p>



<p>next string and these strings don&#8217;t need to be contiguous they could be located anywhere it&#8217;s</p>



<p>that is contiguous but it&#8217;s just full of pointers to other strings or sorry it&#8217;s full of if we de</p>



<p>reference the stack pointer at any point then we will get the address of a string so then we will</p>



<p>get a pointer to a string this double pointer stuff sometimes i get tongue tongue tired okay so uh</p>



<p>when we&#8217;re done printing and incrementing then we just jump to the top of the loop</p>



<p>And then finally, when we&#8217;re done, well, we&#8217;re done.</p>



<p>Let me draw this out for you, because I think the way I&#8217;m explaining it might be</p>



<p>a little bit unclear, so I just want to make sure that I&#8217;m being totally clear on</p>



<p>this, okay, so I&#8217;ve got my little annotator here and you can imagine here&#8217;s a stack</p>



<p>and it visually grows up.</p>



<p>We can imagine that every time we add an item to the stack, it grows up.</p>



<p>Like if you wanted to take a five, stick it on top of the stack.</p>



<p>Well, then it would end up on the top of the stack, right?</p>



<p>No problem.</p>



<p>Right? No problem.</p>



<p>Oh, maybe this needs to be bigger because of my pen size.</p>



<p>So let&#8217;s do it like that.</p>



<p>What the heck happened?</p>



<p>I lost the whole desktop.</p>



<p>There we go.</p>



<p>So we have this and this and this and this.</p>



<p>And so there&#8217;s probably some kind of a value sitting on top of the stack.</p>



<p>When we started the program,</p>



<p>RSP is a register that just has the memory location of the top of the stack,</p>



<p>you know, the most recently added item.</p>



<p>you know the most recently added item we know that this was actually arg c so if we dereferenced rsp</p>



<p>that&#8217;ll go to wherever rx is and get it so we can basically say that rx is sitting on the top of</p>



<p>the stack so you know we dereference our rsp which holds a memory location to this place in memory</p>



<p>we just had an integer stored an eight byte integer okay cool so then the next lowest i guess</p>



<p>the next highest item or the next lower item is arg v at index zero which is the same thing as</p>



<p>just saying arg v remember a pointer to the array is really a pointer to the first item</p>



<p>the next lower item is arg v at index one and so forth so we can just keep doing this we can keep</p>



<p>keep doing this we can keep going lower and lower and lower on the stack by adding eight to r13</p>



<p>because remember r13 originally pointed uh you know to this item right here i don&#8217;t know i&#8217;ll</p>



<p>say like r13 maybe starts off pointing uh to the first argument because that&#8217;s the way we have it</p>



<p>set up so every time the loop iterates if we dereference r13 then we&#8217;re getting a pointer to</p>



<p>when we add eight bytes to r13 we&#8217;re really just moving it down to the next pointer that we can</p>



<p>dereference hopefully that was a little bit more clear than what i said before or maybe you&#8217;re just</p>



<p>a visual learner um you know it&#8217;s a good idea to try to explain things in many different ways</p>



<p>but long story short we&#8217;re going down down down further in the stack to get more arguments and</p>



<p>we&#8217;re just printing them and so now that we&#8217;ve explained it all we should be able to just run</p>



<p>clear and make run and under the hood let me just show you real fast what I&#8217;ve got inside of my make</p>



<p>file under the hood when we do make run you don&#8217;t need to know about make files I have a video that</p>



<p>explains all of this don&#8217;t worry but well I mean you don&#8217;t need to know it to understand this video</p>



<p>but you probably do need to know it notice how when I call the executable which in this case is</p>



<p>I give it some arguments.</p>



<p>I give it just some strings.</p>



<p>First arg, second arg, third arg, fourth arg.</p>



<p>So that&#8217;s the same thing as if I typed echo first arg,</p>



<p>second arg, third arg, fourth arg, right?</p>



<p>That&#8217;s what echo is doing.</p>



<p>So in the make file, I&#8217;m just giving it those arguments.</p>



<p>And then our program now is looping</p>



<p>through all of the arguments.</p>



<p>It knows when to stop because we grabbed argc</p>



<p>and it knows where those strings are located</p>



<p>are located because the pointers to those strings are just sitting on the stack so if we deref twice</p>



<p>we&#8217;re derefing we&#8217;re doing a double dereference a pointer to a pointer</p>



<p>at least we could say r13 is a pointer to a pointer but the actual values sitting inside</p>



<p>the stack are just pointers to strings um so let&#8217;s just do this in a slightly different way</p>



<p>clear and then I&#8217;ll say main because that&#8217;s the name of the program that I</p>



<p>compiled you can imagine this is could be named something else and I&#8217;ll just put</p>



<p>hello you are super cool now so I&#8217;m giving it one two three four five</p>



<p>arguments in addition to main so it should print six things main hello you</p>



<p>are super cool now so notice how it prints main hello you are super cool now</p>



<p>Alright, that&#8217;s pretty much everything that I wanted to show you for the pure assembly</p>



<p>version of Grappin Command Line Arguments.</p>



<p>Thank you so much for listening.</p>



<p>It&#8217;s a little late for me.</p>



<p>The sun&#8217;s starting to come up.</p>



<p>I&#8217;ve got to go and eat a bunch of cookies.</p>



<p>So I hope you learned some stuff and I hope you had a little bit of fun.</p>



<p>Thank you so much for watching this video.</p>



<p>I will see you in the next one.</p>



<p>Happy studying and coding and all that stuff.</p>



<p>Hey everybody!</p>



<p>Thanks for watching this video again from the bottom of my heart.</p>



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



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



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



<p>could you please subscribe and follow this channel or these videos</p>



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



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



<p>It would really mean the world to me and it&#8217;ll help make more videos</p>



<p>and grow this community.</p>



<p>So we&#8217;ll be able to do more videos, longer videos, better videos,</p>



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



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



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



<p>happens every single time so you could do it as a nice favor to me or you could you control me if</p>



<p>you want to just wake me up in the middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake</p>



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



<p>of the screen right now you should see a qr code which you can scan in order to go to the website</p>



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



<p>main website where you can just kind of like see all the videos i published and the services and</p>



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



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



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



<p>the night i get i wake up in a cold sweat and i&#8217;m like it would really it really mean the world to</p>



<p>me i would really appreciate it so again thank you so much for watching this video and um enjoy the</p>



<p>cool music as as i fade into the darkness which is coming for us all</p>



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/">Master Command Line Arguments in x86-64 Assembly with YASM</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-command-line-arguments-in-x86-64-assembly-with-yasm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
