<?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>dereferencing assembly Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/dereferencing-assembly/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/dereferencing-assembly/</link>
	<description></description>
	<lastBuildDate>Sun, 22 Feb 2026 03:21:33 +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>dereferencing assembly Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/dereferencing-assembly/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>x86-64 Assembly Pointers &#038; Dereferencing Explained &#8211; Hybrid C++/YASM Example</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 22 Feb 2026 03:21:32 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly C++ interop]]></category>
		<category><![CDATA[assembly data section]]></category>
		<category><![CDATA[assembly memory addresses]]></category>
		<category><![CDATA[assembly pointers]]></category>
		<category><![CDATA[assembly tutorial]]></category>
		<category><![CDATA[dereferencing assembly]]></category>
		<category><![CDATA[extern C assembly]]></category>
		<category><![CDATA[hybrid C++ assembly]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[passing pointers assembly]]></category>
		<category><![CDATA[stack alignment assembly]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[x86-64 calling convention]]></category>
		<category><![CDATA[x86-64 pointers]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=305</guid>

					<description><![CDATA[<p>This video explains pointers and dereferencing in x86-64 YASM assembly and demonstrates passing pointers between assembly and C++ in a hybrid program. We show how to read a C string from assembly, modify a long via pointer dereference so the change is visible in C++, and send assembly-owned data (string, long, double) back to C++ using pointers.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/">x86-64 Assembly Pointers &amp; Dereferencing Explained &#8211; Hybrid C++/YASM Example</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="x86-64 Assembly Pointers &amp; Dereferencing Explained - Hybrid C++/YASM Example" width="1380" height="776" src="https://www.youtube.com/embed/jzj0iqC-XJI?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>Learn pointers &amp; dereferencing in x86-64 YASM assembly and how to pass them correctly between assembly and C++ in a hybrid program. We build a small working example that sends strings, longs, and doubles both directions using pointers, modifies values across module boundaries, and explains why pointer-to-double still uses general-purpose registers. Includes a quick demo of stack misalignment crash + fix.</p>



<p>Great for assembly beginners moving to real programs, systems programming students, or anyone curious how low-level code talks to C/C++.</p>



<p>00:00 Introduction to Pointers and Dereferencing in x86-64 Assembly<br>00:28 Pointers explained in C++<br>01:02 Changing values via pointers in C++<br>01:43 Pointers in assembly basics<br>02:09 Defining variables and pointers in YASM data section<br>03:23 Pointers are always integers even to doubles<br>04:20 Function arguments are pointers treated as 64-bit integers<br>05:00 Driver C++ code overview<br>05:58 Marking extern &#8220;C&#8221; functions<br>06:40 Local stack variables and passing pointers<br>07:51 Stack lifetime warning<br>08:34 Assembly data section strings and numbers<br>09:39 Print null-terminated string helper functions<br>10:38 External symbols and hey_driver_print_this<br>11:29 Point function prologue and stack alignment<br>13:04 Extra push for 16-byte alignment<br>14:20 Printing welcome message from assembly<br>16:00 Driver sees initial long value<br>16:58 Printing received string from C++<br>18:20 Using received char pointer without dereference<br>20:21 Modifying incoming long via dereference<br>21:46 Driver sees modified long value 101<br>22:43 Calling back to C++ to print assembly-owned data<br>23:48 Passing pointers to assembly string long and double<br>25:08 Driver prints assembly-owned values and addresses<br>26:14 Summary of pointer passing between modules<br>26:36 Stack alignment crash demonstration<br>27:39 Adding extra push/pop fixes segfault<br>28:00 Closing remarks and call to subscribe</p>



<p>=-=-=-=-=-=-=-=-=</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>



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



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



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



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



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



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



<p>Please show your support!</p>



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



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



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



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



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



<p>Hey there! In this video we&#8217;re going to talk about pointers and dereferencing in a YASM x8664</p>



<p>assembly program, also as a hybrid program so that assembly and C++ can talk to each other</p>



<p>and send each other pointers and send each other data and things like that.</p>



<p>for what pointers are.</p>



<p>I&#8217;m going to write in C++ for a second.</p>



<p>Suppose you have a pointer for an integer.</p>



<p>We&#8217;ll call it P.</p>



<p>Suppose you have an integer by itself.</p>



<p>We&#8217;ll call it A.</p>



<p>Let&#8217;s say that the value of A is 5.</p>



<p>And if you wanted to say that P points to A,</p>



<p>you could say P equals the address of A.</p>



<p>I&#8217;ll put C++ at the top here.</p>



<p>And so now if I set A to 6</p>



<p>then I print P a dereference of P this is not like a full pointers tutorial</p>



<p>but basically by changing a I&#8217;m changing what P thinks it sees as a value</p>



<p>assuming ID reference it I could also let me do a print 6 here I could also</p>



<p>just change the value through P I could say dereference P and I could say equals</p>



<p>would actually print a seven right so you know you can have regular variables global variables</p>



<p>whatever kind of you know memory stuff on the stack and to get a pointer to it you really just</p>



<p>need to get its memory location in c++ it&#8217;s kind of easy syntactically you can see what&#8217;s happening</p>



<p>in assembly you really just need the memory location stored somewhere you could store that</p>



<p>variable that just simply stored the memory location of some other variable.</p>



<p>You could have a 64-bit register store the value of a variable.</p>



<p>Let&#8217;s say we have like a, I don&#8217;t know, my whatever, my number let&#8217;s say inside of assembly.</p>



<p>I&#8217;ll do ASM here and we say it&#8217;s a quad word and it starts off as this number or whatever.</p>



<p>So if you haven&#8217;t seen my previous videos, go see them for the basics of assembly and</p>



<p>of assembly and linking and make files and all that stuff but you know if you</p>



<p>have an assembly program and you have a data section and you define a global</p>



<p>variable like this what you&#8217;re basically saying is I want to take this giant</p>



<p>number and I want to write it into eight bytes that&#8217;s the DQ it says data quad</p>



<p>word I want to write that giant number across eight bytes and then I want to</p>



<p>get a pointer to it stored in the my number symbol so my number is not</p>



<p>actually the value it&#8217;s a pointer to the value so you know later if you want to</p>



<p>you know later if you want to move you know something into a register if you did this</p>



<p>that would move the pointer into rax but if you did this</p>



<p>with deref symbols after it or around it then you would move</p>



<p>maybe i&#8217;ll put that into rex you&#8217;d move that actual number that we specified into rex</p>



<p>into Rx. It&#8217;s important to understand also that pointers are integers even when we&#8217;re pointing to</p>



<p>doubles. So for example sometimes people make this mistake they&#8217;ll say you know my double</p>



<p>and they&#8217;ll say it&#8217;s a quad word meaning this is going to be a 64-bit double precision floating</p>



<p>point number and they&#8217;ll do like 44.55 or whatever. So that is a double and it is in memory</p>



<p>you know what is the symbol of my double remember it&#8217;s supposed to be just a</p>



<p>pointer right it can&#8217;t be an actual double because a memory location is not</p>



<p>a double a memory location is an integer so that means if you wanted to move a</p>



<p>pointer into a register you would only be able to move the pointer into a</p>



<p>regular general purpose register not a floating point register and you should</p>



<p>use the regular movement instructions for just regular general purpose</p>



<p>So keep that in mind if you see a signature like this like let&#8217;s say function F and we have</p>



<p>You know, let&#8217;s say long a and long B and actually let&#8217;s do pointers</p>



<p>Let&#8217;s say long pointer a and long pointer</p>



<p>B and double pointer C all three of those arguments are actually 64 bit integers</p>



<p>Because they&#8217;re all pointers even if one of the pointers points to adult a double</p>



<p>double why did I say dull pointers aren&#8217;t dull they&#8217;re exciting okay so I&#8217;m gonna open up some</p>



<p>code here real fast so usually I don&#8217;t explain my uh my driver I&#8217;m gonna explain it to you this time</p>



<p>because it&#8217;s kind of doing a little bit more than my other videos um again if you don&#8217;t have uh the</p>



<p>knowledge of how to make a make file see my other videos because that&#8217;s explained there for now I&#8217;m</p>



<p>what we really need to do is write a driver and an assembly module for a</p>



<p>hybrid program again hybrid programs covered in other videos so the driver is</p>



<p>pretty easy I&#8217;m just going to copy paste it honestly here and then just kind of</p>



<p>explain it to you the driver is pretty easy we&#8217;re going to do I O stream so we</p>



<p>can print stuff we&#8217;re going to mark an external function called point as extern</p>



<p>C so that just disables name mangling which means the C++ module will be able</p>



<p>will be able to call on this function called point and it won&#8217;t expect that</p>



<p>the point function has its name mangled like C++ does the reason being is that</p>



<p>point is actually going to be in a side it&#8217;s going to be inside assembly where</p>



<p>its name will not be mangled this disables the ability to overload but</p>



<p>that&#8217;s okay we don&#8217;t care it&#8217;s going to take two pointers a pointer to a character</p>



<p>and a pointer to a long since both of those are pointers they&#8217;re both</p>



<p>64-bit integers even the character pointer and then we have a function that is internal to this</p>



<p>module called hey driver print this remember we&#8217;re inside of the driver program right now</p>



<p>so if you look at the bottom it&#8217;s just a function that takes in some pointers</p>



<p>and then prints some stuff so it&#8217;s going to print like it&#8217;s going to print what the string is</p>



<p>it&#8217;s going to print what the long is my dog&#8217;s growling at me i&#8217;m going to ignore him because</p>



<p>i literally just let him pee and poop at this point now he&#8217;s harassing me for treats</p>



<p>now he&#8217;s harassing me for treats he always does this okay so uh the string the long the double</p>



<p>this function expects to receive three pointers to different data types it&#8217;s just going to print</p>



<p>all of them and the point get it the point of this function is we&#8217;re going to go inside of</p>



<p>the assembly module and then have the assembly module call on this function so that we can we</p>



<p>can prove that we can have stuff sent from assembly to c plus plus or c using pointers</p>



<p>using pointers we can have data sent over so anyway that&#8217;s why both of these</p>



<p>are in here the point needs to be marked as no name mangling because point is</p>



<p>inside of assembly which will not name mangle and then hey driver print this</p>



<p>that needs to have name mangling disabled also so that the assembly</p>



<p>module can call on this other than that we&#8217;re just basically inside of a main</p>



<p>saying hey this is the c string we&#8217;re making a c string inside of the main function notice how</p>



<p>this is a local variable so that c string is going to show up on the stack it&#8217;s going to show up in</p>



<p>the area that is owned by main for main stack area same thing for my long that&#8217;s a local variable on</p>



<p>the stack um and but then we can actually send pointers to those pieces of data to another</p>



<p>function in another module you don&#8217;t have to only transport globals or stuff on the heap</p>



<p>or stuff on the heap, you can transport pointers to local variables. Just make sure that by the</p>



<p>time this function finishes, then nowhere else is actually using that data because,</p>



<p>well, being on the stack, once main function or once any function finishes, then its portion of</p>



<p>the stack will be cleaned up and removed and it&#8217;ll be junk data. You&#8217;ll probably get a seg fault.</p>



<p>But for now, we&#8217;re not going to use anything on the stack. We&#8217;re not going to use these local</p>



<p>just going to use them quickly on this call to point and then we&#8217;re going to return to the</p>



<p>operating system and finish the program. So that&#8217;s the driver. Now the hard part. Let&#8217;s do this in</p>



<p>assembly. So for starters, I&#8217;m going to make a data section and just explain it to you very,</p>



<p>very quickly. Again, if you don&#8217;t understand the basics of YASM x86-64 assembly, did I mention</p>



<p>that that&#8217;s what this language is at the beginning of the video? I guess I should put that in the</p>



<p>put that in the description or record an announcement that I can tack on at the beginning</p>



<p>or something. Anyway, so if you don&#8217;t understand how to do this, see my other videos, but basically</p>



<p>we&#8217;re going to make a data section. We&#8217;re going to define some strings. Here&#8217;s like an announcement.</p>



<p>Oh, we&#8217;re inside of, you know, the module now, the assembly module. And now we&#8217;re going to print</p>



<p>the received string. And then we&#8217;re going to make a string that is owned by assembly, which we can</p>



<p>into C++ when we call the function inside of the driver.</p>



<p>So this string is owned by the assembly module.</p>



<p>Notice how these are null terminated strings.</p>



<p>I just have like a comma zero there,</p>



<p>which means I have some extra functions</p>



<p>I&#8217;m gonna paste in that we&#8217;re not really gonna talk about</p>



<p>because they&#8217;ve been discussed in other videos</p>



<p>just so that we can print null terminated strings.</p>



<p>Then I&#8217;ve got a new line here,</p>



<p>you know, carriage return line feed.</p>



<p>And then I&#8217;ve just got some numbers</p>



<p>that are owned by the assembly module.</p>



<p>Then I&#8217;ve got a system write call,</p>



<p>call code one for the system call writes and file descriptor standard output so I</p>



<p>can print just to the terminal again if you don&#8217;t understand this see my other</p>



<p>videos so now let&#8217;s start the actual text section so this is where our</p>



<p>instructions start so we got the text section here and we&#8217;re going to use some</p>



<p>external symbols don&#8217;t worry about these I&#8217;m just using my own little library to</p>



<p>and input integers if you have access to this library use it if you don&#8217;t if you&#8217;re watching</p>



<p>at home and you don&#8217;t have this library then that&#8217;s fine you can use you know printf or</p>



<p>scanf or something like that to get and print floats from and to the user</p>



<p>but yeah I&#8217;m just using that and then I&#8217;m marking an external function here called hey driver print</p>



<p>this if you recall the driver module has a function called hey driver print this so</p>



<p>just allows my assembly code to call on that external function. Okay now next</p>



<p>piece of code. This is going to be… actually I&#8217;m going to paste the print</p>



<p>null terminated string function and related code because it&#8217;s just like a</p>



<p>big giant mess and we&#8217;re mostly going to ignore it. So just to show you what I&#8217;m</p>



<p>doing here I have a function called print null terminated string so that I</p>



<p>can print these strings up here and then I have it rely on a function called</p>



<p>string length that I have implemented up here and all it does is just</p>



<p>implemented up here and all it does just calculates the length of the string and</p>



<p>then a crlf function so I can just call that so that&#8217;s all explained in other</p>



<p>videos don&#8217;t worry about it for now we&#8217;re going to start the actual entry</p>



<p>point remember the driver was just gonna call point right so now we just have to</p>



<p>implement point in the assembly module so that&#8217;s gonna be like down here our</p>



<p>our entry point so the signature for this function is going to be character</p>



<p>pointer and then a long pointer and it doesn&#8217;t return anything and remember</p>



<p>that if we look back at the driver that should match the signature right it&#8217;s a</p>



<p>character pointer and a long pointer and of course this is just a comment that</p>



<p>reminds me of what to do in assembly you don&#8217;t really have a signature you just</p>



<p>sort of use registers but I&#8217;m reminding myself that RDI is going to be a</p>



<p>character pointer and RSI is going to be a long pointer.</p>



<p>Here&#8217;s a note to myself that I&#8217;m going to use R12 and R13, which means</p>



<p>the first thing that I should do, well actually before I even do that, I should</p>



<p>return from this function because it is a function. I marked it as global</p>



<p>so that the other module could call it, the driver module could call it. Again,</p>



<p>see my other videos for hybrid programs.</p>



<p>But so now the, you know, if the driver calls this function, then now we&#8217;re inside of</p>



<p>and there&#8217;s a return statement so it&#8217;s a valid function I should preserve the</p>



<p>registers that I&#8217;m going to use that are marked as Kali saved for the ABI so I&#8217;m</p>



<p>going to go prologue and then an epilogue and I&#8217;m going to say push r12 and push</p>



<p>r13 and then I&#8217;m going to pop r13 pop r12 they should be in reverse order if</p>



<p>you&#8217;ve seen my other videos you&#8217;ll know this and the the thing about this</p>



<p>the thing about this particular program is we&#8217;re going to run into stack alignment issues</p>



<p>so uh if you don&#8217;t know about stack alignment and how it can crash your program without you</p>



<p>realizing what&#8217;s wrong see my other videos but for now we&#8217;ll assume you know that and uh i i</p>



<p>already know from running this program in advance that it&#8217;s going to be out of alignment by eight</p>



<p>bytes so i&#8217;m just going to push an extra register onto the stack and that&#8217;s going to put it back</p>



<p>I know it looks weird, but this is going to work.</p>



<p>Let me get rid of this here.</p>



<p>Okay, so.</p>



<p>And then maybe if I can remember at the end of the video,</p>



<p>I can just remove that extra push-pop pair,</p>



<p>and you&#8217;ll see the program starts crashing.</p>



<p>But at home, you can do it just to double check.</p>



<p>So the first thing I really want to do is,</p>



<p>after I push and pop,</p>



<p>is save our incoming arguments.</p>



<p>Remember, the first integer argument</p>



<p>and the second integer argument,</p>



<p>argument they come in as RDI and RSI in assembly per the ABI if both of these</p>



<p>things are pointers it doesn&#8217;t matter what the data type is it could be</p>



<p>pointing to anything including a double and these would still be considered</p>



<p>integer arguments because well RDI and RSI are just going to be loaded up with</p>



<p>memory locations which which are integers so I&#8217;m going to save our</p>



<p>arguments to R12 and R13 now justifying our push and pop pair then I&#8217;m going to</p>



<p>little welcome message so print a little welcome message again you don&#8217;t need to know about this</p>



<p>function but it&#8217;s explained in other videos that I&#8217;ve already published we&#8217;re going to print our</p>



<p>hello beginning message I&#8217;m getting nervous he needs to take a second poop sometimes it&#8217;s poopoo</p>



<p>number two time for him and he&#8217;s not really just lying about a treat but he did go pee and poop</p>



<p>But he did go pee and poop already.</p>



<p>Okay, he just left and walked away.</p>



<p>Okay, if he comes back, I&#8217;m letting him out this time.</p>



<p>I&#8217;ll pause the video if he does it again.</p>



<p>Okay, I&#8217;m pausing the video.</p>



<p>No pee lied.</p>



<p>He went outside, lifted up his little leg, and a couple of drops of pee came out.</p>



<p>Now he&#8217;s staring at me like he deserves a treat.</p>



<p>Sorry, buddy.</p>



<p>I wish I could eat constantly all day long, too.</p>



<p>But life isn&#8217;t always fair.</p>



<p>isn&#8217;t always fair anyway let&#8217;s see I might even lined up on the camera</p>



<p>anymore I don&#8217;t even know so we&#8217;re looking at this code here is going to</p>



<p>print a welcome message let&#8217;s see if that actually works so I&#8217;m gonna do make</p>



<p>run again make files are whoops what did I do loader dot asm what did I do what</p>



<p>did I do I somehow copy pasted the wrong make file</p>



<p>What&#8217;s the name of my source code file?</p>



<p>It&#8217;s point.</p>



<p>I guess I&#8217;ll just change it, and then it&#8217;ll probably work.</p>



<p>It&#8217;s still in assembly module.</p>



<p>Hopefully that didn&#8217;t mess it up too bad by copy-pasting the wrong source code.</p>



<p>Okay.</p>



<p>What is going on here?</p>



<p>Floater.</p>



<p>Oh, I need to change that.</p>



<p>Hang on.</p>



<p>Let me fix this.</p>



<p>I don&#8217;t know if I&#8217;m going to edit this out.</p>



<p>out. It&#8217;s fun to watch me struggle sometimes. There we go.</p>



<p>Point.</p>



<p>Alright, let&#8217;s give it another try.</p>



<p>Oh no, star dot so no such file a directory. Dang it.</p>



<p>Okay, now this seems to work. I may or may not have edited</p>



<p>that out. I copy pasted the wrong source code into my make</p>



<p>file. So I had to manually adjust it. Then I forgot to</p>



<p>copy paste my library file into the build directory. So I had</p>



<p>The driver sees my long as whatever.</p>



<p>What&#8217;s going on?</p>



<p>Print an alternate string begin.</p>



<p>Oh, the driver is printing a bunch of stuff.</p>



<p>Okay.</p>



<p>I started to think, why does it look like the program has a lot of stuff going on?</p>



<p>Oh, that&#8217;s the driver.</p>



<p>Okay.</p>



<p>So the driver says it sees its long as 100.</p>



<p>And then now we&#8217;re inside of the point module.</p>



<p>So that&#8217;s the only thing we&#8217;ve done in assembly so far.</p>



<p>so far then the driver has regained control maybe I should add a couple of</p>



<p>new lines in there so I don&#8217;t get confused again we will do a C out and L</p>



<p>and we&#8217;ll do two of those run the program again and then I won&#8217;t get</p>



<p>confused about the messages okay so now we&#8217;re inside of the point module and</p>



<p>nothing is happening so points let me get rid of the make file here and</p>



<p>and we&#8217;re just printing a welcome message nothing else so now let&#8217;s print</p>



<p>the received string so what am I talking about so we&#8217;re gonna print a prefix</p>



<p>basically saying hey we received the following string right so if you look at</p>



<p>the symbol message received string it&#8217;s just gonna say we&#8217;re now printing the</p>



<p>received string and then it&#8217;ll print it so what are we actually printing we&#8217;re</p>



<p>What is R12? R12 is a character pointer to the print me string. And so basically this</p>



<p>function print null terminated string, it takes a character pointer. So we&#8217;re giving it a character</p>



<p>pointer that we received. When point was called by the driver, notice how it gave a pointer to</p>



<p>the C string. You know, all arrays are basically pointers. They&#8217;re just different syntactically</p>



<p>just different syntactically sometimes so if i declare an array of some length and i give the</p>



<p>symbol somewhere that symbol is really a character pointer so um by calling point with my c string</p>



<p>i&#8217;m calling point inside of the assembly module with this character pointer so that means even</p>



<p>though this c string is owned by the driver by the c plus plus module the assembly module has access</p>



<p>So that means we should be able to print it right now already.</p>



<p>So just the rest of it is just like giving a pointer.</p>



<p>And notice how I&#8217;m not dereferencing R12.</p>



<p>If I did dereferencing around R12, then we would be looking to that address and seeing what&#8217;s there,</p>



<p>which wouldn&#8217;t work for printing a null terminated string.</p>



<p>So let&#8217;s just run it again.</p>



<p>I don&#8217;t know if you can hear him.</p>



<p>This dude is growling at me still because he wants another treat.</p>



<p>He just got denied.</p>



<p>He&#8217;s trying to do it again.</p>



<p>do it again. I let him outside people. He&#8217;s been outside like three times already and he just went</p>



<p>out like two minutes ago. Okay. I love him so much. It hurts my heart and he knows eventually he&#8217;s</p>



<p>going to break me because it hurts my heart or I&#8217;m like too distracted. It&#8217;s like, you know,</p>



<p>pulling the crank on a slot machine in Vegas. You know, eventually something comes out.</p>



<p>That&#8217;s what he does to me. I&#8217;ve accidentally trained him. So now printing the received</p>



<p>Now printing the received string and notice how it prints.</p>



<p>Hello, this is a C string owned by me.</p>



<p>So our assembly module is able to print a C string that was created locally by a C++ module.</p>



<p>So we&#8217;re handing around pointers.</p>



<p>Nice.</p>



<p>Can you hear me?</p>



<p>He&#8217;s getting louder.</p>



<p>So now let&#8217;s modify the incoming long.</p>



<p>Can you shush your freaking pants, please?</p>



<p>Shush your pants.</p>



<p>shush your pants you know the sad thing also is he&#8217;s so old that he&#8217;s deaf now</p>



<p>so he used to know what shush your pants meant it meant I&#8217;m not listening to you</p>



<p>and you might as well stop because I&#8217;m not gonna do anything based on your</p>



<p>harassment but now he can&#8217;t hear me say shush your pants so he just harasses me</p>



<p>all day and all night okay um so I&#8217;m gonna copy paste a little bit more code</p>



<p>Modify the incoming long.</p>



<p>So remember again that the point function, it received a pointer to a long.</p>



<p>We&#8217;re calling the long change me on the inside of this, but it&#8217;s coming in as R13.</p>



<p>And if you notice what I&#8217;m doing here is I&#8217;m just saying let&#8217;s increase the long.</p>



<p>So I&#8217;m going to dereference R13 because R13 is a pointer.</p>



<p>So I&#8217;m saying let&#8217;s go to the memory and change the long that is inside of memory.</p>



<p>And we have to specify that it is a keyword.</p>



<p>it as a keyword so that we you know we don&#8217;t confuse the system the system might think are</p>



<p>you modifying a keyword or like a double word or like a word like how big is your data all we know</p>



<p>is it&#8217;s an integer because it&#8217;s the increase instruction so I&#8217;m saying we got a keyword you</p>



<p>know a 64-bit integer sitting at that memory location I want you to dereference it and increase</p>



<p>it and going back to the driver we&#8217;re providing a pointer to our long so the long starts off is 100</p>



<p>and we&#8217;re just giving a pointer to it the next thing that we can do is we can</p>



<p>ask the driver to print our own stuff actually you know what let&#8217;s run the program right now</p>



<p>just to show that the driver can see the change in the long so i&#8217;m going to run it again notice how</p>



<p>first when the driver says hello it sees its own long as 100 then we&#8217;re inside the assembly module</p>



<p>long and then we return to the caller which is the driver notice how at the</p>



<p>very end of the program the driver sees its long as being 101 so we were able to</p>



<p>modify data that was owned by a different module just by passing pointers</p>



<p>and de-referencing them okay cool so now the next thing that we should do is let&#8217;s</p>



<p>ask the driver to print our own stuff that we own because remember if you go</p>



<p>to the very top you know we own some stuff we own some we own a long we own</p>



<p>float, right? So we want to be able to do something with that. So I&#8217;m going to copy paste this,</p>



<p>ask the driver to print our own stuff. So I&#8217;m going to move three items inside of arguments</p>



<p>for a function call. And then I&#8217;m going to make a function call calling the function,</p>



<p>Hey driver, print this again, Hey driver, print this is actually owned by the C++ module.</p>



<p>a pointer to a long and a pointer to a double remember even pointers to doubles are actually</p>



<p>integers so they use the general purpose register so that&#8217;s the three arguments right there rdi rsi</p>



<p>and rdx m and then we&#8217;re giving the first pointer is going to be the c string so message string</p>



<p>inside asm so you can see that&#8217;s this right here and then the next pointer is the long</p>



<p>inside ASM and the third is the float where did I just go I&#8217;m getting confused my dog is harassing</p>



<p>me right now so bad notice how I&#8217;m not dereferencing so like if when we were increasing the incoming</p>



<p>long before R13 was a pointer so we dereferenced while we increased so that we would increase the</p>



<p>actual value and not the pointer and not the pointer&#8217;s memory location but here we&#8217;re not</p>



<p>C++ module the actual pointers to our data. We don&#8217;t want to give it the data itself. We want</p>



<p>to give pointers to the data so we&#8217;re not derefing with the brackets. So then we call it and when we</p>



<p>get back in here it should just be able to print everything. So I&#8217;m going to run it one more time.</p>



<p>We&#8217;re going to make it and run it and so now let&#8217;s see. So here we&#8217;re inside of our assembly module</p>



<p>And then here the assembly module has just called on hey driver print this.</p>



<p>Remember the C++ module doesn&#8217;t actually call this function.</p>



<p>The assembly module calls it.</p>



<p>So we&#8217;re like going back and forth.</p>



<p>We&#8217;re kind of crisscrossing.</p>



<p>So now the drivers print this function says we got the following string.</p>



<p>Notice how that&#8217;s the string that is owned by assembly.</p>



<p>So we define that inside of our data section in the assembly module.</p>



<p>And then it prints the long.</p>



<p>It prints it as hex.</p>



<p>And it just sort of prints the value.</p>



<p>it just sort of prints the value then it prints it as hex again and then prints at the value</p>



<p>i think actually not hex i think this prints the memory location let&#8217;s double check real fast</p>



<p>yeah so remember um in c plus plus i know this is not like a c plus plus video but um</p>



<p>if the long is a pointer then if we just print it without dereferencing it we should see a memory</p>



<p>location so it&#8217;s telling us uh that the long&#8217;s memory location is this and the doubles memory</p>



<p>location is that and if you stare at those two numbers long enough and you understand hex which</p>



<p>And do you understand hex, which you can see my other videos for?</p>



<p>You&#8217;ll see that those memory locations are right next to each other because that&#8217;s the way we define them inside of assembly.</p>



<p>So we now have the ability to have data that is owned by assembly and give it to C++ or C using pointers.</p>



<p>No problem at all.</p>



<p>And then the printing driver thing exits and then the actual driver regains control.</p>



<p>And it just says that it sees it&#8217;s long as 101.</p>



<p>it sees it&#8217;s long as 101 so uh yeah that&#8217;s that&#8217;s pretty much all i wanted to show you for this</p>



<p>now you hopefully are an expert at passing data back and forth between various modules using</p>



<p>pointers we&#8217;re not using references because references are like a little bit a little bit</p>



<p>less compatible pointers are just really easy they totally work in assembly no problem</p>



<p>one more thing i just wanted to show you real fast before we go even though there&#8217;s another</p>



<p>video you should check out for stack alignment I just want you to see what</p>



<p>happens if I remove this extra push-pop pair so now my stack is about eight</p>



<p>bytes off of its previous alignment because you know we&#8217;re not pushing an</p>



<p>extra eight byte value and somewhere inside of the let&#8217;s see print null</p>



<p>terminated string and then the hey driver print this oh and then we go into</p>



<p>like a bunch of C stuff the program should probably crash because anytime</p>



<p>you use a GCC function or a GCC library or something like that the stack has to</p>



<p>be aligned to 16 bytes so if it&#8217;s off by 8 then it&#8217;ll crash and how did I know</p>



<p>that I needed this well I just ran it first and it crashed and then I added</p>



<p>the extra push pop pair and it didn&#8217;t crash and I realized it was definitely</p>



<p>one more time we should get a seg fault yeah we get a seg fault stack alignment oh no with no</p>



<p>description of what&#8217;s going on if you were in gcc you could i mean sorry if you were in gdb you</p>



<p>could probably figure that out eventually but why not just give it a try add another push pop pair</p>



<p>run the program again with no other modifications now it totally works</p>



<p>okay well uh i think that&#8217;s uh that&#8217;s all i have for this video thank you so much for watching i</p>



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



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



<p>Hey everybody.</p>



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



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



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



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



<p>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</p>



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



<p>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 do me a</p>



<p>kindness and and subscribe you know sometimes I&#8217;m sleeping in the middle of</p>



<p>the night and I just wake up because I know somebody subscribed or followed it</p>



<p>just wakes me up and I get filled with joy that&#8217;s exactly what happens every</p>



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



<p>up in the middle of the night just subscribe and then I&#8217;ll just wake up I promise that&#8217;s what will</p>



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



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



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



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



<p>for</p>



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



<p>What&#8217;s up? What&#8217;s going on? You know, just send me a comment, whatever</p>



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



<p>It would really it really mean the world to me. I would really appreciate it. So again, thank you so much for watching this video and</p>



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



<p>Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/">x86-64 Assembly Pointers &amp; Dereferencing Explained &#8211; Hybrid C++/YASM Example</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-pointers-dereferencing-explained-hybrid-c-yasm-example/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Tue, 23 Dec 2025 13:22:17 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[dereferencing assembly]]></category>
		<category><![CDATA[gdb debugging assembly]]></category>
		<category><![CDATA[general purpose registers]]></category>
		<category><![CDATA[integer data movement]]></category>
		<category><![CDATA[lea instruction]]></category>
		<category><![CDATA[low level programming]]></category>
		<category><![CDATA[mov instruction assembly]]></category>
		<category><![CDATA[pointer arithmetic assembly]]></category>
		<category><![CDATA[pointers in assembly]]></category>
		<category><![CDATA[systems programming]]></category>
		<category><![CDATA[ubuntu assembly programming]]></category>
		<category><![CDATA[x86 assembly tutorial]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm tutorial]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=269</guid>

					<description><![CDATA[<p>This practical x86-64 assembly language tutorial explains integer data movement between registers and memory, the importance of data size specifiers (byte, word, dword, qword), the difference between pointers and dereferenced values, pointer arithmetic for array access, and using LEA for address calculation - all demonstrated with YASM on Ubuntu Linux and inspected via GDB.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/">x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</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="x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)" width="1380" height="776" src="https://www.youtube.com/embed/zGrnEPrpmeg?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>In this hands-on x86-64 assembly tutorial, we dive deep into moving integer data between registers and memory, working with pointers, dereferencing, and pointer arithmetic using YASM on Ubuntu.</p>



<p>You&#8217;ll see practical examples of:</p>



<ul class="wp-block-list">
<li>Moving immediates and data between general-purpose registers</li>



<li>Loading different sized integers (byte, word, dword, qword) from memory</li>



<li>Why data size specifiers matter and what happens with overflow/underflow</li>



<li>The difference between moving a pointer vs dereferencing it</li>



<li>Pointer arithmetic to access array elements</li>



<li>Using LEA for address calculation without dereferencing</li>



<li>Debugging with GDB to inspect registers step-by-step</li>
</ul>



<p>Perfect for anyone learning low-level programming, systems programming, or wanting to truly understand how pointers work at the assembly level. No prior expert knowledge required &#8211; we build it up with clear examples.</p>



<p>Code and examples are shown live, compiled with YASM, linked with LD, and debugged with GDB.</p>



<p>If you&#8217;re into assembly, reverse engineering, operating systems, or just love understanding how computers really work, this one is for you.</p>



<p>Introduction to Integer Data Movement and Pointers 00:00:00<br>Program Setup and Makefile 00:01:16<br>Data Section Definitions 00:01:38<br>System Calls for Output and Exit 00:01:52<br>Text Section and Entry Point 00:04:21<br>Printing Hello String 00:05:05<br>Moving Immediates to Registers 00:06:04<br>Copying Between Registers 00:06:27<br>Dereferencing Pointers from Memory 00:07:16<br>Specifying Data Sizes 00:08:01<br>Register Size Variants 00:09:45<br>Reference Book Explanation 00:10:50<br>Loading Words and Bytes 00:13:25<br>Debugger Breakpoint and Registers 00:14:28<br>Overflow Demonstration 00:16:25<br>Makefile Adjustments for Warnings 00:17:44<br>Proving Data Size Importance 00:20:32<br>Underflow and Overflow Examples 00:21:34<br>Symbols as Pointers 00:24:16<br>Array Definitions and Access 00:25:20<br>Pointer to Array Items 00:26:08<br>LEA Instruction for Addresses 00:27:32<br>Dereferencing Manipulated Pointers 00:29:01<br>Final Register Inspection 00:29:50<br>Conclusion and Subscribe Request 00:33:26</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 everybody! In this video I&#8217;m going to talk to you about integer data movement and pointers</p>



<p>in an x86-64 YASM assembly program within Ubuntu but this should work for all of you x86 YASM people.</p>



<p>Okay so what am I talking about for starters? I&#8217;m just talking about moving data pretty much. If you</p>



<p>from one integer register to another or from one general purpose register to another.</p>



<p>And if you know how to manipulate pointers in assembly and all that stuff,</p>



<p>you probably don&#8217;t need this video.</p>



<p>But if you are not an expert, then this will probably help you.</p>



<p>Let me start off by saying, of course, that there are going to be lots of concepts in this video</p>



<p>that I don&#8217;t actually explain because I&#8217;ve explained them in other videos.</p>



<p>For example, this is not a Hello World tutorial where I show you how to actually,</p>



<p>you know, build a basic Yasm assembly program.</p>



<p>a basic yasm assembly program you can probably infer that just from this video but i&#8217;m not going</p>



<p>to explain it also this is not a debugging video so i&#8217;m not really going to explain too much about</p>



<p>gdb which is something i&#8217;m going to use to look at the registers but it might be nice for you to</p>



<p>get a little preview i will record a full gdb tutorial in another video anyway so let&#8217;s see</p>



<p>here uh for starters i&#8217;ve just kind of like created a little sample program here um well</p>



<p>a make file which will just compile and execute my program again this is not a</p>



<p>make file video tutorial check my other videos for that I&#8217;ve already made one</p>



<p>for now I&#8217;m just gonna start making a program and I&#8217;m gonna give it a data</p>



<p>section so first thing I&#8217;m gonna give it is like well let&#8217;s say I&#8217;ll give it a</p>



<p>bunch of data then I&#8217;ll kind of explain what I gave it again this is not a</p>



<p>basics Yasum tutorial so see my other videos but you know just simply put I&#8217;m</p>



<p>You know just simply put I&#8217;m gonna write to standard output so I do I remember the system call code for for writing</p>



<p>And then I&#8217;m gonna exit because this is a pure assembly program that I&#8217;m compiling. There&#8217;s this is not a hybrid program</p>



<p>We&#8217;re not doing GCC. We&#8217;re just doing LD</p>



<p>So I&#8217;m just gonna say a call code 60 to exit a file descriptor for stdin actually I don&#8217;t really need that</p>



<p>Let me just double check that I don&#8217;t need that in my solution</p>



<p>Yeah, I like to reuse these things so we don&#8217;t really need standard input</p>



<p>standard input. We&#8217;re just going to do standard output, you know, printing to the terminal.</p>



<p>We&#8217;re going to exit with a success code of zero. And then I made a couple of, well, just one C</p>



<p>string where I&#8217;m just basically saying, hello, my name is so-and-so. So you can know that the</p>



<p>program actually started in case it crashes later. That&#8217;s not my name. I just love those kinds of</p>



<p>names. And then I&#8217;m just going to make a bunch of integers of different data sizes. So this is kind</p>



<p>sizes but just real fast because these are going to be directly used in our video we uh we have a</p>



<p>quad word here so i&#8217;m defining an integer called my long int and i&#8217;m saying that it&#8217;s a quad word</p>



<p>with dq q for quad word and then i&#8217;m just giving a pretty big integer same thing for a regular d</p>



<p>word which is just a double word so that&#8217;s half of a quad word and then another thing with a whoops</p>



<p>w not a q let me just fix that in my solution oh dear then i&#8217;m going to do a word which is a six two</p>



<p>one one one a word is two bytes of data we&#8217;re starting to get dangerously into overflow territory</p>



<p>when i was originally writing this solution i had like a bunch of nines up here and the number that</p>



<p>i ended up seeing on the screen was totally different and i forgot oh a word is just two bytes</p>



<p>so even if it&#8217;s unsigned the highest thing that it can actually represent is um</p>



<ol start="65535" class="wp-block-list">
<li>So that&#8217;s not good. Then I&#8217;m going to just store a byte here with DB and put some twos there.</li>
</ol>



<p>And then I&#8217;m going to make an array of integers. Putting an array, making an array in the regular</p>



<p>data section, that&#8217;s not as good as putting it in the BSS section if you want a lot of integers.</p>



<p>But I&#8217;m just going to specify a small number of integers so I can just put it directly into the</p>



<p>BSS is for like giant arrays of uninitialized data and the data section is for whatever you can handle typing pretty much of initialized data.</p>



<p>So now I&#8217;m going to start my text section and my program&#8217;s entry point.</p>



<p>Again, this is not a Yasm basics tutorial. See my other videos.</p>



<p>And so we&#8217;re going to start by just saying here&#8217;s my entry point where the operating system can sort of jump into my program.</p>



<p>to just you know exit the program let&#8217;s actually see if that works so far it</p>



<p>should do nothing but but at least exit with success I&#8217;m gonna go clear and make</p>



<p>run and notice how it just kind of like ran it and then nothing happened okay so</p>



<p>that&#8217;s great how come it didn&#8217;t print though what did I do wrong oh I forgot</p>



<p>to copy paste the code that prints something okay let me get my solution up</p>



<p>here so the first thing we&#8217;re really going to do is just use a system call to</p>



<p>call to print the word hello again this is not a system call video see my other videos</p>



<p>and um so now we&#8217;re just we&#8217;re just going to print our hello string</p>



<p>with a system call let me run it one more time we should see like a quick hello</p>



<p>yeah okay my name is uh chaplain mondover it&#8217;s not maybe i should change that to it&#8217;s not my name is</p>



<p>not no i don&#8217;t want to do that sometimes i like to pretend that my name is chaplain mondover</p>



<p>name is check lane Mondover you should too it&#8217;s fun anyway so the first thing that I&#8217;m going to</p>



<p>do here is I&#8217;m going to move an immediate well let me copy paste a whole chunk of code and then</p>



<p>I&#8217;ll explain it one by one I&#8217;m basically going to use data movement instructions to move a bunch of</p>



<p>data into a bunch of registers and then I&#8217;m going to hit a break point or I&#8217;m going to I&#8217;m going to</p>



<p>sort of do like a non-operation piece of code so that I can easily break on it in my debugger so</p>



<p>the results. Okay so first off I&#8217;m going to move an immediate into R12. The</p>



<p>instruction for moving data into general purpose registers or the integer</p>



<p>registers is just MOV so that&#8217;s fine probably you should know that by now but</p>



<p>I&#8217;m going to move an immediate into R10 and I&#8217;m going to move 12876 into R10.</p>



<p>So that&#8217;s how you move an immediate no problem. Then I&#8217;m going to first clear</p>



<p>out R11 and then I&#8217;m going to move R10 into it. The reason I&#8217;m clearing out R11</p>



<p>reason i&#8217;m clearing out r11 first is just to prove to you that we are actually moving data from one</p>



<p>register into another because if i just i don&#8217;t know if i didn&#8217;t do that you might be tempted to</p>



<p>to think well um maybe r11 already had that data in it so first it&#8217;s going to be just a zero and</p>



<p>then it&#8217;s going to actually be whatever r10 had so we should see r10 and 11 both have one two eight</p>



<p>register or a pointer register from one to another. And by the way, integers, those are</p>



<p>pointers, or rather, should I say, pointers are integers. So if you&#8217;re moving an integer or you&#8217;re</p>



<p>moving a pointer, the system just kind of sees that as a number either way. So you can use the</p>



<p>move instruction for it. So now let&#8217;s use the pointer that was assigned to our long integer</p>



<p>to move that number into R12. So let me just go up real fast. My long int up here,</p>



<p>my long int up here it&#8217;s like a gigantic number and remember I said before that my long int is</p>



<p>actually just a pointer to the memory location that begins to hold the quad word so my long</p>



<p>int is really a pointer to one byte and there&#8217;s an eight byte allocation because it&#8217;s a quad word</p>



<p>so when you sort of put this into your code and you let the system know that you want to move a</p>



<p>then the system will scan eight bytes and interpret that as an integer so</p>



<p>putting the the keyword quad word here I don&#8217;t think that&#8217;s necessary I usually</p>



<p>do it anyway but you&#8217;ll see in the next few instructions that it&#8217;s a really</p>



<p>really good idea to specify the data size because if you don&#8217;t you&#8217;re gonna</p>



<p>actually get something wrong in other words if for some reason I moved I don&#8217;t</p>



<p>into R12 I could do it if I if I wrote it correctly but then I would be taking</p>



<p>part of a quad word and trying to interpret that as the entire number and</p>



<p>it&#8217;s probably going to be totally wrong we&#8217;ll have an example for that in a</p>



<p>moment but anyway so that&#8217;s how we move a quad word we just specify keyword right</p>



<p>before the memory location and we use the brackets to dereference if we</p>



<p>didn&#8217;t dereference then we would actually be moving a pointer to the long</p>



<p>integer into R12 we&#8217;ll do that soon too I&#8217;m going to try to do everything in this</p>



<p>to do everything in this video then we&#8217;ll move a d word from uh from memory into r13 this is a</p>



<p>little bit different notice how uh here on line 60 i kind of have to specify d word because that&#8217;s</p>



<p>the data size that i&#8217;m trying to move into the r13 register so this is telling the system that</p>



<p>there&#8217;s about four bytes that i need to scan not eight bytes and interpret those four bytes as an</p>



<p>Moving it into R13, you know, I could have sworn a long time ago, you could just move that sort of thing directly into R13.</p>



<p>But when I tried my solution before recording this video, I kept getting assembler errors until I added the D at the end.</p>



<p>And so I just want you to know, oh, you know what, let&#8217;s look at a book real fast.</p>



<p>Let&#8217;s look at my favorite book.</p>



<p>I just want you to know that there are other forms of every register that can specify the register&#8217;s data size.</p>



<p>What do I mean by that?</p>



<p>itself then the system thinks you&#8217;re talking about all 64 bits of the 13 register the r13 register</p>



<p>but if you type whoops if you type r13d then the system thinks you&#8217;re only talking about the lowest</p>



<p>32 bits of that register so you&#8217;re also able to specify the data size of a register again i thought</p>



<p>you should should a long time ago i thought i remembered moving a d word directly into r13 and</p>



<p>it would just clear out the extra bits but i got warnings this time maybe that&#8217;s for the best</p>



<p>that&#8217;s for the best forcing us to be more precise, but this will solve it. R13 just says,</p>



<p>let&#8217;s only talk about a D word. So let me go, let me go to my favorite book here.</p>



<p>Where the heck is my favorite book? Okay. I guess I have to like, there we go.</p>



<p>Okay. There&#8217;s my favorite book. So, um, I&#8217;m going to go to, uh, let&#8217;s, let me just search for,</p>



<p>just search for I can&#8217;t remember where it is our 13 D yeah there it is okay so</p>



<p>what we&#8217;re looking for is 2.3.1.1 let me show you real fast the top of the book</p>



<p>just to give a shout out to the person who wrote this book I did not write this</p>



<p>book this is a free and open source book that you can download for free</p>



<p>everybody should get a copy to turn yourselves into an expert it&#8217;s called</p>



<p>x86 64 assembly language programming with Ubuntu it&#8217;s written by a brilliant</p>



<p>professor. This is like a semi recent version. There&#8217;s probably a newer one now, but yeah,</p>



<p>it&#8217;s a great book. I love it. So I&#8217;m going to go back to what the heck was I just doing?</p>



<p>Was it 2.3.1.1? Yeah. Okay. So in this book section 2.3.1.1, the section entitled general</p>



<p>purpose registers, notice how there are a bunch of different versions of each register. So if you</p>



<p>So if you look in this column right here, we have, oh, I get to use my annotator.</p>



<p>We have a, what were we just looking at?</p>



<p>R12.</p>



<p>Notice how R12 here is a designated as a 64 bit register.</p>



<p>But if you wanted to use the R12 register and only use 32 bits of it, the lowest 32</p>



<p>bits, then this is the form you would use for the R12 register.</p>



<p>So 32 bits.</p>



<p>And if you wanted to use only a word&#8217;s worth, you know, 16 bits.</p>



<p>Well there you go.</p>



<p>two bytes on these systems or 16 bits and then if you just wanted to use one</p>



<p>byte of the register well you can you just put a B at the end of it it&#8217;s</p>



<p>pretty sweet and convenient it&#8217;s not too hard to remember that D is for D word and</p>



<p>W is for word and B is for bytes it just gets a little confusing when you&#8217;re</p>



<p>using the other registers like the the RAX register it&#8217;s got EAX as its 32-bit</p>



<p>version and then AX as its 16-bit version and AL as its 8-bit version if</p>



<p>it&#8217;s a 8-bit version if you can remember that there&#8217;s an L I guess that&#8217;s not too bad but you</p>



<p>know remembering the X and then it changes to an I over here and a P over here I&#8217;m personally not</p>



<p>a fan so I always come back to this book to try and remember what I&#8217;m supposed to be putting for</p>



<p>these registers because I can&#8217;t remember all the time or rather I can almost never remember but we</p>



<p>So, I want to take a D word from memory and load it up into the R13 register.</p>



<p>So I got to specify the R13D.</p>



<p>And, you know, maybe I&#8217;ll take that out and show you that it doesn&#8217;t compile later, if I can remember.</p>



<p>But I&#8217;m going to now take a D word, do the same thing into R13.</p>



<p>Oh, sorry, no.</p>



<p>I&#8217;m going to take a regular word and do the same thing basically into R14.</p>



<p>But it&#8217;s just going to be a word instead of a D word.</p>



<p>And then I&#8217;m going to take a single byte and load it up into R15.</p>



<p>single byte and load it up into R15. Then I&#8217;m going to call Nope, which is an instruction that</p>



<p>just does nothing. And it&#8217;s useful sometimes if you want to have a place where you can stop your</p>



<p>program and sort of inspect the results of your program in your debugger. So there&#8217;s a lot more</p>



<p>to this program. I&#8217;m going to go ahead and just run it right now, just to make sure that it compiles.</p>



<p>And then maybe I&#8217;ll add a breakpoint here. Let&#8217;s go clear and make run. Okay, so it ran,</p>



<p>Okay, so it ran, it compiled, it was fine.</p>



<p>And now I&#8217;m going to open up a new little window and I&#8217;m going to launch the program.</p>



<p>Notice how the program that has been compiled is called main.</p>



<p>So I&#8217;m going to launch the program into the GDB debugger.</p>



<p>This is not a GDB video.</p>



<p>So I&#8217;m going to be skimming over this, check future videos for a full GDB tutorial.</p>



<p>So I&#8217;m going to do a break point right there at line 72.</p>



<p>So that I can just kind of inspect the state of the register.</p>



<p>break at main.asm line 72 and then just to be sure I did that correctly I&#8217;m going to say info</p>



<p>breakpoints or just a b is fine and it&#8217;s like looks like I set it up correctly then I can type</p>



<p>run to see what&#8217;s up notice how it starts to run and immediately stops at that breakpoint</p>



<p>you can tell it stops there because it&#8217;s at line 72 then I&#8217;m just going to do info registers or</p>



<p>info r just to print out all my registers and we should see a confirmation of what we were hoping</p>



<p>so if I kind of like maybe I&#8217;ll pin this to the top for a second always on top how about that</p>



<p>so first we moved an immediate into r10 so notice how 12876 is in r10 right there and then on line</p>



<p>53 we basically copied r10 into r11 so that means in r11 we see the same value</p>



<p>and then we&#8217;ll move a quad word from the long integer we&#8217;ll dereference that pointer</p>



<p>at R12 it&#8217;s like this gigantic number if I scroll all the way up it&#8217;s the same number here as in our</p>



<p>source code so that seemed to work and then we&#8217;re going to move the D word next I guess into R13</p>



<p>so that&#8217;s this number right here so that seemed to have worked it&#8217;s this number right here the</p>



<p>D word and I&#8217;m going to get lost so fast scrolling up and down like this now we&#8217;re going to move a</p>



<p>one one and there it is right there and then r15 is just gonna take a bite and</p>



<p>it&#8217;s gonna take a bite oh now I&#8217;m hungry now I&#8217;m hungry that activated it it&#8217;s</p>



<p>only been like think four or five hours since I ate I guess that is usually when</p>



<p>I need to eat again even though I gorge and fall asleep on the floor because I</p>



<p>home r15 anyway holds the correct value it&#8217;s 222 i just want to show you overflow real fast</p>



<p>we look at r14 uh we&#8217;re using the word version so it&#8217;s only going to read you know uh two bytes</p>



<p>from that memory location and it&#8217;s only going to consider uh you know 16 bits as being valid in uh</p>



<p>in that register so if i use a number that&#8217;s too big it&#8217;ll overflow two bytes the maximum number</p>



<p>three, five or from zero to that number or six, five, five, three, six combinations.</p>



<p>So if I just stick a nine in front of that right now, that should overflow the system.</p>



<p>So let me try it one more time.</p>



<p>I want to do Q because that was the last thing we needed to look at.</p>



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



<p>Oh gosh, what&#8217;s happening here?</p>



<p>Okay.</p>



<p>How about I do clear and make build, which is in my make file and GDB main.</p>



<p>So I don&#8217;t have to type all this stuff out again every single time.</p>



<p>have to type all this stuff out again every single time what did i just do oh nice okay you know what</p>



<p>i swear it didn&#8217;t used to do this before it&#8217;s giving me a nice warning saying that value does</p>



<p>not fit in a 16-bit field i guess if i turned warnings off which i don&#8217;t want to do then the</p>



<p>program would run and it would overflow eh do you want to turn it off let&#8217;s turn off warnings okay</p>



<p>much attention to it. Um, where the heck are the warnings? Where&#8217;s the assembler running? There it</p>



<p>is. Yasum flags. And that&#8217;s, so that&#8217;s my variable up there. There we go. Okay. So I&#8217;m just going to</p>



<p>make a copy of this line, comment out the original, and then I&#8217;m going to take out, uh, the command</p>



<p>that says, or the flag that says convert warnings into errors. Your compiler is your friend. It was</p>



<p>So I am now going to do a breakpoint at 72.</p>



<p>So break at main.asm972 and then run and then it breaks.</p>



<p>And then I go input registers.</p>



<p>Then if I look at, what was I just talking about?</p>



<p>R14, was that it?</p>



<p>Notice how 44607 for the word, that&#8217;s a totally different value, right?</p>



<p>So this is what happens when you overflow or underflow.</p>



<p>You got to be careful about your data sizes.</p>



<p>I&#8217;m just going to do this again one more time just to make sure.</p>



<p>one more time just to make sure that it&#8217;s fixed now that I moved it and I&#8217;m</p>



<p>gonna I&#8217;m gonna read that part about warnings because I love converting</p>



<p>warnings to errors as just a way to help myself write better code okay so let&#8217;s</p>



<p>do that and you know what I&#8217;m gonna do too I added another target here again</p>



<p>this is not a Yasm or sorry this is not this is kind of a Yasm video this is not</p>



<p>extra file called gdb.txt where I can stick gdb commands and so I don&#8217;t want</p>



<p>to continue to type my breakpoints over and over over again every single time so</p>



<p>I know for sure I&#8217;m not going to change the program anymore at least I&#8217;m not</p>



<p>going to shift the lines up and down before 72 so I&#8217;m going to do breakpoint</p>



<p>you can type like break or I think you can type either break or the full word</p>



<p>breakpoint but I just type B name of the source code file a.asm at line 72 and so</p>



<p>And so this file right here, again, this is not a GDB tutorial, but in my make file, I have it set up so that GDB will execute whatever commands I put into this text file.</p>



<p>So it just kind of saves me typing.</p>



<p>So let&#8217;s put a breakpoint there and then we&#8217;ll say info breakpoints and then we&#8217;ll just run the program in that way.</p>



<p>I can have a little bit more information.</p>



<p>So I&#8217;m going to do make build instead of make build and then running GDB.</p>



<p>I&#8217;m going to say make debug.</p>



<p>That&#8217;s another target in my make file.</p>



<p>make file so then you can see it added the breakpoint for me and then it</p>



<p>immediately broke on that and you know what yeah I guess I&#8217;ll just leave it in</p>



<p>where I have to type info registers okay so we&#8217;re just making sure I think that</p>



<p>R14 is still a valid value and that it was fixed okay so we&#8217;ve gotten this far</p>



<p>the next thing we need to do is prove that data size matters by specifying a</p>



<p>specifying a bad data size for our long and then for our byte. So I&#8217;m going to copy paste a little</p>



<p>proof here that is followed by another non-operation. So I&#8217;m going to do this. And so</p>



<p>I&#8217;m going to try to prove to you that the data size matters by specifying a bad data size. I</p>



<p>just proved to you that it kind of mattered or it definitely mattered in terms of overflow and</p>



<p>underflow, but I&#8217;m trying to prove to you now that it matters when you&#8217;re reading. So I&#8217;m going to</p>



<p>I&#8217;m going to clear out r12 and then I&#8217;m going to move a byte from the long integer into r12b</p>



<p>and you know this would be a warning or I think it this wouldn&#8217;t compile or wouldn&#8217;t assemble if</p>



<p>I didn&#8217;t have the b there so I&#8217;m basically telling the computer all right I want you to use only a</p>



<p>byte of r12 and I want you to take one byte from memory and just put it in there but I&#8217;m taking it</p>



<p>awful. And then right after that, I&#8217;m going to do another naughty thing. I&#8217;m going to move</p>



<p>something into R15 and I&#8217;m going to word, I&#8217;m going to move a keyword of memory into R15,</p>



<p>but I&#8217;m going to be taking it from the bytes memory. So remember a byte is just one byte.</p>



<p>And so the next seven bytes that come after it definitely have nothing to do with that byte,</p>



<p>but I&#8217;m going to interpret them all as a quad word. So we should get nonsense data</p>



<p>also R15. I don&#8217;t really need to zero out R15 because the fact that I&#8217;m specifying R15 means</p>



<p>I want to use all 64 bits. So it is going to definitely zero it out. And whatever we see in</p>



<p>R15 is going to be the real thing. But in terms of R12B, we&#8217;re only going to be loading up one</p>



<p>byte&#8217;s worth of that register. So that&#8217;s why I&#8217;m zeroing out the rest of it just to prove to you</p>



<p>that we are truly getting nonsense. So now there&#8217;s going to be another break point at 82.</p>



<p>I&#8217;m not going to break anymore at 72. I&#8217;m going to break at 82. So let&#8217;s do that.</p>



<p>What&#8217;s going on here? We got that.</p>



<p>Oh gosh. Okay. Quit. I guess that means I need to comment this out. Let me do that.</p>



<p>We&#8217;ll do break at main.asm at 82. And you could, you could do both of these two. Actually,</p>



<p>let me do it first. We could, we could do multiple break points. Yeah, I&#8217;ll just do it first,</p>



<p>So notice how it first breaks at the 72 and then I do C to continue and then suddenly</p>



<p>it breaks at the 82.</p>



<p>But I don&#8217;t want to have to hit continue a bunch of times so I&#8217;m going to comment that</p>



<p>out for the future.</p>



<p>Let me quit real fast to make sure I remember what GDB expects as a comment.</p>



<p>Yeah, okay.</p>



<p>82.</p>



<p>Okay, so then I&#8217;m going to print the registers info registers.</p>



<p>And we&#8217;re looking at R12 and R15.</p>



<p>You can see R12 has the number 144, which definitely doesn&#8217;t make sense because there&#8217;s</p>



<p>no 144 anywhere in our original data.</p>



<p>in our original data so hopefully that&#8217;s proof to you that we&#8217;ve grabbed some junk</p>



<p>sometimes maybe when you&#8217;re doing this at home if you&#8217;re just going to grab one bite</p>



<p>maybe accidentally um no no that would definitely still look bad but for the r15</p>



<p>if you&#8217;re going to grab a q words worth of data i don&#8217;t know maybe the junk data is like</p>



<p>accidentally correct in a way where it would it would still make it look like the intended value</p>



<p>the intended value no it wouldn&#8217;t there&#8217;s no way that would even happen no i guess the junk data</p>



<p>could could work that way anyway so we&#8217;ll look at r15 two eight and a bunch of fours and then a two</p>



<p>three eight um that value does not exist up here so again junk data mixed in with real data is is</p>



<p>bad news okay so now let&#8217;s do another proof i want to prove to you that symbols are pointers</p>



<p>you know like I&#8217;ve been saying and they need to be dereferenced so let&#8217;s first start off by</p>



<p>moving the raw pointer for my long int into r10 and then into r11 we will dereference that</p>



<p>pointer so in r10 we should see something that looks like a memory location or at least a relative</p>



<p>memory location and then in r11 we should see the actual long integer like we saw before</p>



<p>And then I&#8217;m going to mess around with some arrays.</p>



<p>So remember up here we made an array.</p>



<p>Let me minimize that real fast.</p>



<p>We made an array, a very small array.</p>



<p>I just specified a bunch of ones and then specified a bunch of twos.</p>



<p>So it should be contiguous memory since it&#8217;s been allocated as an array with that comma</p>



<p>there.</p>



<p>We should see if we looked inside of the system inside of memory, we should see eight bytes</p>



<p>representing the ones.</p>



<p>And then right next to that, we should see eight bytes representing the twos.</p>



<p>easy for us to sort of move our pointer around a little bit. So what else do I need to copy paste</p>



<p>here? We got that long int. Okay. So I&#8217;m going to grab the first item and the second item in those</p>



<p>arrays just using some pointer manipulation. So you know how to do this already. You just take</p>



<p>like the pointer to some number and you just dereference it and you end up getting a number.</p>



<p>I understand your feeling because you might be thinking, wait a minute, wait a minute.</p>



<p>I understood it when it was dereferencing just one number, but didn&#8217;t you say this is an array?</p>



<p>Why is it we can dereference the array and just get one number still?</p>



<p>Well, remember, a pointer to an array is really a pointer to the first item in the array.</p>



<p>That&#8217;s kind of how it works.</p>



<p>So either way, whether you consider that to be a pointer to one number or a pointer to array,</p>



<p>when we dereference it, we&#8217;ll get one number.</p>



<p>If you want to get the other numbers, then you have to start manipulating the pointer</p>



<p>or derefing in different ways.</p>



<p>So here&#8217;s how we can get the second item.</p>



<p>We deref the original pointer plus 8.</p>



<p>8 because it&#8217;s a quad word.</p>



<p>So, you know, it probably would be a little smarter to put that 8 up into a define somewhere</p>



<p>so you&#8217;re not hard coding numbers, but I&#8217;m not going to do it.</p>



<p>So basically in R12, we should see the 1s.</p>



<p>In R13, we should see the 2s.</p>



<p>And then a couple more things.</p>



<p>Next, we will grab a pointer to the first item in the small array.</p>



<p>And we&#8217;ll just stick that into R14.</p>



<p>So, you know, we kind of did that with R10 already.</p>



<p>But now I just want a pointer to the small array.</p>



<p>And I&#8217;m going to keep it in R14 just so you can see the memory location.</p>



<p>And then after that, we&#8217;re going to grab an actual pointer to the second item.</p>



<p>hey how do you get a pointer to the second item well it&#8217;s that but then what</p>



<p>if you didn&#8217;t want to dereference the pointer like what if R13 you know here</p>



<p>clearly because we have these brackets for dereferencing you&#8217;re allowed to put</p>



<p>the formulas inside of the brackets what if I wanted to get the address to the</p>



<p>second item and not actually the second item we would not be allowed to remove</p>



<p>the brackets the assembler wouldn&#8217;t like that so without another instruction</p>



<p>way to actually get a pointer with a complicated mathematical formula. You know, you can do like</p>



<p>multiplication inside of here and other things in parentheses. So we wouldn&#8217;t be able to do that</p>



<p>without the other instruction that I&#8217;m introducing now called LEA. LEA just means, yeah, sure, we&#8217;re</p>



<p>still going to use the brackets to figure out where the pointer is, like figure out what memory</p>



<p>location we want with some sort of a formula. But then what will be stored in the first operand is</p>



<p>This LEA won&#8217;t dereference just because there are brackets.</p>



<p>LEA will keep the pointer.</p>



<p>And then finally, once we actually have a pointer to the second item in R15,</p>



<p>then we can move the second item into another register.</p>



<p>And this is like an LOL because I ran out of registers already.</p>



<p>So I&#8217;m just going to use RDI, which is usually the first argument.</p>



<p>It doesn&#8217;t matter. It&#8217;s fine.</p>



<p>So if we dereference R15, it&#8217;s the same thing as dereferencing this.</p>



<p>We could have also just dereferenced R14,</p>



<p>and it would have been the same thing as just getting the value of the first item.</p>



<p>But I hope you can see now that, you know,</p>



<p>that expression is going to be a pointer to the second item in the array,</p>



<p>and that&#8217;s going to be stuck into R15.</p>



<p>So if we dereference that, we can treat R15 like a pointer.</p>



<p>It&#8217;s just, you know, it&#8217;s a general purpose register.</p>



<p>it doesn&#8217;t only need to hold integer values it can also hold pointers because pointers are integers</p>



<p>they&#8217;re just unsigned so we deref the pointer that is stored inside of r15 now put it inside</p>



<p>of rdi and then we should see that rdi actually holds the second item which should be a bunch of</p>



<p>twos so the last thing that i&#8217;m going to copy paste in here is another nope so i&#8217;m going to</p>



<p>break at 108 just so we can see the rest of it so i&#8217;m going to open up this right here and i&#8217;m</p>



<p>open up this right here and I&#8217;m going to comment that out and I&#8217;m gonna say break at 108.</p>



<p>Whoops.</p>



<p>Okay.</p>



<p>There we go.</p>



<p>But, but, but quitsies.</p>



<p>Now I&#8217;m just going to run make debug again so that I can enter GDB.</p>



<p>And we&#8217;ve, we&#8217;ve, we&#8217;ve hit our break points.</p>



<p>And now I&#8217;m going to go info registers and just talk about the stuff that we&#8217;re seeing.</p>



<p>Okay.</p>



<p>So the first thing I think this is all on one page, right?</p>



<p>I don&#8217;t need to scroll.</p>



<p>Yeah.</p>



<p>one page right I don&#8217;t need to scroll yeah okay this is all on one page first thing we see is r10</p>



<p>holds this value right here that&#8217;s a pointer to the my long int that kind of looks like a pointer</p>



<p>if you consider that it could be relative and then r11 holds the actual integer and if you recall</p>



<p>that is the gigantic long that we put in there great so now that&#8217;s the difference between a</p>



<p>pointer and its value or in its dereference value so then we&#8217;re going to grab the first item in the</p>



<p>So then we&#8217;re going to grab the first item in the small array.</p>



<p>So R12 should have the ones.</p>



<p>If we look at R12 here, it&#8217;s got the ones.</p>



<p>Again, just trying to prove to you that if you dereference a pointer to an array,</p>



<p>you&#8217;re actually dereferencing a pointer to the first item.</p>



<p>And then on R13, we&#8217;re going to make a pointer to the second item.</p>



<p>Then with the brackets and the move instruction, we dereference that and it should become the twos.</p>



<p>So if we look at R13, notice how it&#8217;s the twos.</p>



<p>Then we&#8217;re going to grab a pointer to the first item in the small array.</p>



<p>Hang on a second.</p>



<p>What did I want to say about that?</p>



<p>In the small array to R14.</p>



<p>Okay.</p>



<p>So again, we&#8217;re just going to grab an actual pointer to the small array.</p>



<p>And so the difference between R12 and R14 is the dereft value or the pointer.</p>



<p>So if we look at R12, that&#8217;s the actual value that we&#8217;re pointing at.</p>



<p>And then R14 is the memory location that we have in there.</p>



<p>And then notice how it&#8217;s kind of similar.</p>



<p>Notice how it&#8217;s kind of similar.</p>



<p>Maybe this proves a little bit more that these are pointers that we&#8217;re looking at.</p>



<p>R10 was supposed to be a pointer and now R14 is also a pointer.</p>



<p>Notice how those numbers are pretty close together.</p>



<p>I&#8217;m sure if we looked back up in the data section and we calculated an offset based</p>



<p>on how big each data item was, we could probably predict what the memory location of R14 should</p>



<p>have been based on R10 because you can see it&#8217;s like only increased by a little bit,</p>



<p>by a little bit right it was like 534 to 49 what is that 10 plus 5 so that&#8217;s like 15 is that correct</p>



<p>oh I guess I had a byte in there so maybe it&#8217;s that&#8217;s why it&#8217;s kind of odd but yeah we can we</p>



<p>can just compute the offset and then we&#8217;ll grab a pointer to the second item using the LEA</p>



<p>instruction remember we have to use brackets if we&#8217;re going to do an expression but then the</p>



<p>dereferencing in the move instruction so we just use LEA to not dereference.</p>



<p>So we should see that R15 is about 8 bytes further along in RAM than R14 because both of those items</p>



<p>are contiguous in memory and they should only be about you know a quad word apart 8 bytes.</p>



<p>So if we look at R14 it&#8217;s got this number so it&#8217;s a pointer and then if we look at R15</p>



<p>you know what&#8217;s 49 plus 8 it&#8217;s 57 so you can see that the pointer to the second item is only</p>



<p>pointer to the second item is only eight bytes further in memory yay contiguousness and then</p>



<p>sorry i can&#8217;t resist so then finally we will uh we&#8217;ll look at the dereference to r15 because it&#8217;s</p>



<p>now a pointer what was it it was the it was a pointer to the second item that should be a bunch</p>



<p>of twos right because remember in our array we had a bunch of twos here as our second item</p>



<p>have a bunch of twos inside of it so if i look at rdi where the heck is that right there has a</p>



<p>bunch of twos inside of it rdi baby oh my gosh why did i say that anyway so that&#8217;s our non-operation</p>



<p>instruction and i think that&#8217;s everything that i wanted to talk to you about in this video so now</p>



<p>i hope you feel like you&#8217;re an expert in moving integers and moving pointers and</p>



<p>dereferencing pointers and manipulating pointers so you can get a pointer to something else and</p>



<p>pointer to something else and de-referencing those pointers or not whenever you choose.</p>



<p>Thank you so much for watching this video. I hope you learned a little bit of stuff</p>



<p>and you had a little bit of fun. I&#8217;ll see you in the next video. Limit out. I&#8217;ll never say that</p>



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



<p>appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



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



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



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



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



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



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



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



<p>night and I just wake up because I know somebody subscribed or followed it just</p>



<p>wakes me up and I get filled with joy that&#8217;s exactly what happens every single</p>



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



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



<p>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>my main website where you can just kind of like see all the videos I published and the services</p>



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



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



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



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



<p>It would really mean the world to me.</p>



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



<p>So again, thank you so much for watching this video.</p>



<p>And enjoy the cool music 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/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/">x86-64 Assembly: Integer Data Movement, Pointers, and Dereferencing Explained (YASM on Ubuntu)</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-integer-data-movement-pointers-and-dereferencing-explained-yasm-on-ubuntu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
