Quick but thorough introduction to floating-point registers in x86-64 assembly using YASM.
Learn why XMM0 is special, how to use MOVSD / MULSD / CVTSI2SD, why you must save floats around function calls, and how easy (or sneaky) stack alignment bugs can crash your program.
Live coding + real examples converting integers to doubles and multiplying them.
Great next step after basic integer assembly tutorials.
00:00 Introduction to Floating Point Registers
00:28 Why Floating Point Uses Special Registers
01:35 Floating Point Return Value in XMM0
02:17 XMM Registers Overview XMM0 to XMM15
02:48 ABI Rules No Callee-Saved XMM Registers
03:16 128-bit XMM Registers Purpose and Size
04:00 Ed Jorgensen x86-64 Textbook Reference
05:03 Locating XMM Documentation in Textbook
05:20 Earthquake – I am going to die
06:24 Chapter 18 Floating Point Instructions
07:34 MOVSS vs MOVSD Single vs Double Precision
09:11 Understanding SS and SD Instruction Suffixes
10:58 MOVSD Example Register to Register
11:03 Conversion Instructions CVT Family
13:02 Floating Point Arithmetic ADDSD MULSD SUBSD
25:48 Program Demo User Input Section
26:01 Converting Integer to Double CVTSI2SD
26:29 Multiplying by Constant Float MULSD
28:56 Saving Result Printing Modified Float
31:38 Multiplying User Integer by User Float
33:54 Final Result Display Program Summary
35:19 Stack Alignment Crash Demonstration
36:24 Conclusion Key Takeaways
36:52 Outro Subscribe and Thanks
=-=-=-=-=-=-=-=-=
Thanks for watching!
Find us on other social media here:
- https://www.NeuralLantern.com/social
- Twitter / X: https://x.com/NeuralLantern
- Rumble: https://rumble.com/c/c-3696939
- BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt
- Daily Motion: https://www.dailymotion.com/neurallantern
- Minds: https://www.minds.com/neurallantern/
- Odysee: https://odysee.com/@NeuralLantern:5
Please show your support!
- Buy me a coffee: https://ko-fi.com/neurallantern
- Subscribe + Sharing on Social Media
- Leave a comment or suggestion
- Subscribe to Blog: https://www.NeuralLantern.com
- Watching the main “pinned” video of this channel for offers and extras
Hey there! In this video we’re going to talk about pointers and dereferencing in a YASM x8664
assembly program, also as a hybrid program so that assembly and C++ can talk to each other
and send each other pointers and send each other data and things like that.
for what pointers are.
I’m going to write in C++ for a second.
Suppose you have a pointer for an integer.
We’ll call it P.
Suppose you have an integer by itself.
We’ll call it A.
Let’s say that the value of A is 5.
And if you wanted to say that P points to A,
you could say P equals the address of A.
I’ll put C++ at the top here.
And so now if I set A to 6
then I print P a dereference of P this is not like a full pointers tutorial
but basically by changing a I’m changing what P thinks it sees as a value
assuming ID reference it I could also let me do a print 6 here I could also
just change the value through P I could say dereference P and I could say equals
would actually print a seven right so you know you can have regular variables global variables
whatever kind of you know memory stuff on the stack and to get a pointer to it you really just
need to get its memory location in c++ it’s kind of easy syntactically you can see what’s happening
in assembly you really just need the memory location stored somewhere you could store that
variable that just simply stored the memory location of some other variable.
You could have a 64-bit register store the value of a variable.
Let’s say we have like a, I don’t know, my whatever, my number let’s say inside of assembly.
I’ll do ASM here and we say it’s a quad word and it starts off as this number or whatever.
So if you haven’t seen my previous videos, go see them for the basics of assembly and
of assembly and linking and make files and all that stuff but you know if you
have an assembly program and you have a data section and you define a global
variable like this what you’re basically saying is I want to take this giant
number and I want to write it into eight bytes that’s the DQ it says data quad
word I want to write that giant number across eight bytes and then I want to
get a pointer to it stored in the my number symbol so my number is not
actually the value it’s a pointer to the value so you know later if you want to
you know later if you want to move you know something into a register if you did this
that would move the pointer into rax but if you did this
with deref symbols after it or around it then you would move
maybe i’ll put that into rex you’d move that actual number that we specified into rex
into Rx. It’s important to understand also that pointers are integers even when we’re pointing to
doubles. So for example sometimes people make this mistake they’ll say you know my double
and they’ll say it’s a quad word meaning this is going to be a 64-bit double precision floating
point number and they’ll do like 44.55 or whatever. So that is a double and it is in memory
you know what is the symbol of my double remember it’s supposed to be just a
pointer right it can’t be an actual double because a memory location is not
a double a memory location is an integer so that means if you wanted to move a
pointer into a register you would only be able to move the pointer into a
regular general purpose register not a floating point register and you should
use the regular movement instructions for just regular general purpose
So keep that in mind if you see a signature like this like let’s say function F and we have
You know, let’s say long a and long B and actually let’s do pointers
Let’s say long pointer a and long pointer
B and double pointer C all three of those arguments are actually 64 bit integers
Because they’re all pointers even if one of the pointers points to adult a double
double why did I say dull pointers aren’t dull they’re exciting okay so I’m gonna open up some
code here real fast so usually I don’t explain my uh my driver I’m gonna explain it to you this time
because it’s kind of doing a little bit more than my other videos um again if you don’t have uh the
knowledge of how to make a make file see my other videos because that’s explained there for now I’m
what we really need to do is write a driver and an assembly module for a
hybrid program again hybrid programs covered in other videos so the driver is
pretty easy I’m just going to copy paste it honestly here and then just kind of
explain it to you the driver is pretty easy we’re going to do I O stream so we
can print stuff we’re going to mark an external function called point as extern
C so that just disables name mangling which means the C++ module will be able
will be able to call on this function called point and it won’t expect that
the point function has its name mangled like C++ does the reason being is that
point is actually going to be in a side it’s going to be inside assembly where
its name will not be mangled this disables the ability to overload but
that’s okay we don’t care it’s going to take two pointers a pointer to a character
and a pointer to a long since both of those are pointers they’re both
64-bit integers even the character pointer and then we have a function that is internal to this
module called hey driver print this remember we’re inside of the driver program right now
so if you look at the bottom it’s just a function that takes in some pointers
and then prints some stuff so it’s going to print like it’s going to print what the string is
it’s going to print what the long is my dog’s growling at me i’m going to ignore him because
i literally just let him pee and poop at this point now he’s harassing me for treats
now he’s harassing me for treats he always does this okay so uh the string the long the double
this function expects to receive three pointers to different data types it’s just going to print
all of them and the point get it the point of this function is we’re going to go inside of
the assembly module and then have the assembly module call on this function so that we can we
can prove that we can have stuff sent from assembly to c plus plus or c using pointers
using pointers we can have data sent over so anyway that’s why both of these
are in here the point needs to be marked as no name mangling because point is
inside of assembly which will not name mangle and then hey driver print this
that needs to have name mangling disabled also so that the assembly
module can call on this other than that we’re just basically inside of a main
saying hey this is the c string we’re making a c string inside of the main function notice how
this is a local variable so that c string is going to show up on the stack it’s going to show up in
the area that is owned by main for main stack area same thing for my long that’s a local variable on
the stack um and but then we can actually send pointers to those pieces of data to another
function in another module you don’t have to only transport globals or stuff on the heap
or stuff on the heap, you can transport pointers to local variables. Just make sure that by the
time this function finishes, then nowhere else is actually using that data because,
well, being on the stack, once main function or once any function finishes, then its portion of
the stack will be cleaned up and removed and it’ll be junk data. You’ll probably get a seg fault.
But for now, we’re not going to use anything on the stack. We’re not going to use these local
just going to use them quickly on this call to point and then we’re going to return to the
operating system and finish the program. So that’s the driver. Now the hard part. Let’s do this in
assembly. So for starters, I’m going to make a data section and just explain it to you very,
very quickly. Again, if you don’t understand the basics of YASM x86-64 assembly, did I mention
that that’s what this language is at the beginning of the video? I guess I should put that in the
put that in the description or record an announcement that I can tack on at the beginning
or something. Anyway, so if you don’t understand how to do this, see my other videos, but basically
we’re going to make a data section. We’re going to define some strings. Here’s like an announcement.
Oh, we’re inside of, you know, the module now, the assembly module. And now we’re going to print
the received string. And then we’re going to make a string that is owned by assembly, which we can
into C++ when we call the function inside of the driver.
So this string is owned by the assembly module.
Notice how these are null terminated strings.
I just have like a comma zero there,
which means I have some extra functions
I’m gonna paste in that we’re not really gonna talk about
because they’ve been discussed in other videos
just so that we can print null terminated strings.
Then I’ve got a new line here,
you know, carriage return line feed.
And then I’ve just got some numbers
that are owned by the assembly module.
Then I’ve got a system write call,
call code one for the system call writes and file descriptor standard output so I
can print just to the terminal again if you don’t understand this see my other
videos so now let’s start the actual text section so this is where our
instructions start so we got the text section here and we’re going to use some
external symbols don’t worry about these I’m just using my own little library to
and input integers if you have access to this library use it if you don’t if you’re watching
at home and you don’t have this library then that’s fine you can use you know printf or
scanf or something like that to get and print floats from and to the user
but yeah I’m just using that and then I’m marking an external function here called hey driver print
this if you recall the driver module has a function called hey driver print this so
just allows my assembly code to call on that external function. Okay now next
piece of code. This is going to be… actually I’m going to paste the print
null terminated string function and related code because it’s just like a
big giant mess and we’re mostly going to ignore it. So just to show you what I’m
doing here I have a function called print null terminated string so that I
can print these strings up here and then I have it rely on a function called
string length that I have implemented up here and all it does is just

