13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 8.1 of Assembly.
Today we're gonna talk about floating point numbers and then floating point operations,
floating point numbers.
So a floating point number is defined. And I, Tripoli seven
as a number for floating point arithmetic. And then the very first bit is the sign bit,
and this represents whether or not the number is either positive or negative.
Then after that, we have the exponents, The exponents says, What power? We're going to raise this number two,
and then we actually have the number which is called the Mantis. A.
So, for example, if we have a single precision number, the sign bit is the first bit.
And then the exponents is the next eight bits, so we can see that they're eight bits here,
and then the Mantis A is the remaining 23 bits, and that gives us a 32 bit number.
If we look at a double precision or a double in the C programming language, the first bit is a sign bit again. The exponents is the next 11 bits. And then the man Tissa is remaining 52 bits
And so each of these gives us Mawr precision. But it also comes at a cost of more memory that we need to use in order to store those numbers.
And then the floating point unit, or F P u has a built in stack. And so it has this own stack that is separate from the regular stack
and, for example, on X 86 machine, it only has eight stack registers. So S T 01234 all the way up to seven,
and then each of these is actually 80 bits. And so if you load a number into them and do some operations, that will give us additional precision that will help and make sure that it could be more accurate. And one of the big things to realize with Floating point is that it's not 100% accurate. So because you're starting storing numbers that could
we have the ability for values to not exactly match up with what we would think of them. When we're talking about decimal
and then SD zero always points to the top of the stack. So it's a last in first out type of thing
so floating point operations.
So, for example, if you want to load something from either memory or
a register, you can use F L d for floating point load and that a loaded onto the top of the stack
and then f i l d saddle loaded imager. And so the i n here stands for energy. So it'll taken an edger and then converted to a floating point.
You can load the constant one or zero if you need those on top of the stack,
and then when we go in store, weaken, say fst so floating point store that will copy it from the floating point stack into the regular stack or into regular memory, depending on where you're doing it.
And then we have this notion of having the ability to pop. So if you see a command like Fs
F A S T P, that means it's going to store, do the first part and then pop off the stack. And so
one of the things you want to make sure is that you don't just keep pushing things onto the stack forever, because then it will break things.
So we have the same thing for an imager so we can take a floating point and copy it to an imager. And we can also pop it off of the stack
and then some of the math operations that we can do. We can see that we have an ad. So s t zero plus the source. So what? Add that in, store it onto SD zero.
We also have the pop versions
on each one of these, and then we have. So we have addition, subtraction, multiplication and division.
And he and each one has a P very into in order for you to pop it off the stack. If you're done using the stack and you want to save it after doing that operation,
and then let's just give ah, quick example.
So here I have a simple program.
So all it's doing is it has a number A in a number B, and it's just using f l d and f STP. So I'm loading it onto the floating point stack and then I'm going to go ahead and store back in to be so I I would have a and I would have be
so I can go ahead and build it. And I just wanted to run this in that the bugger.
So I didn't say GTB,
and then we're gonna break in Assam main,
and then we'll go ahead and start running. So are for run.
So I can step through the 1st 2 instructions here.
So this should load onto the floating point stack.
So if I type i for info and then float, it will show me the floating point stack, and we can see that right now it has nothing.
And then I'm going to go ahead and execute this F l D command.
All right, so it executed that instruction. And if I want again, look at the floating point stack.
I can see that the number 1.98 or with a bunch of nines and one is stored on there,
right? And we got our sign bid are Mantis A and then are some bit are exponents that are Mantis A are on there
and then if we want to look at B to see that it gets saved,
so I'll examine and then efforts for float and then give it the address of B.
We can see that it doesn't have anything
and it looks like a,
um it's reading the value wrong there. But that's OK,
so let's do four f the seafood gifts. All right, so we have 1.99
and so now if we do the next instruction
and then look at our floating point stack,
we can see that
it's still on here, but we're not actually pointing to it. So s t zero points to this. So it actually just leaves it on there and just moves it
away from where it waas.
But if we go and look at B
and I gotta put here four,
we can see that now I got the value that it was supposed to have. So 1.99
So today we talked about the floating point unit and the floating point of stack associated with that and then operations that we can do on floating point numbers gave some examples.
Looking forward, we're going to do more complicated floating point examples and then talk about foot floating point decisions. So selection statements using floating point.
So here's our quiz, but floating point register 20 points to the top of the floating point stack
S t zero.
What is the exponent length for a 64 bit floating? Point number?
If you have questions, you can email me at Miller MJ at you and Kate. I e d u. And you can find me on Twitter at Milhouse 30.
How to Use GDB (BSWJ)
In this part of the Breaking Stuff with Joe (BSWJ) series, Joe Perry demonstrates how ...
Certificate of Completion Offered
How to Use IDA (BSWJ)
The IDA is used throughout the IT and cybersecurity industries by exploit developers, vulnerability analysts, ...
Certificate of Completion Offered