 # Floating Point

Video Activity
Join over 3 million cybersecurity professionals advancing their career
or Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14
Video Transcription
00:01
Hello. This is Dr Miller, and this is Episode 8.1 of Assembly.
00:05
Today we're gonna talk about floating point numbers and then floating point operations,
00:11
floating point numbers.
00:13
So a floating point number is defined. And I, Tripoli seven
00:17
54
00:19
as a number for floating point arithmetic. And then the very first bit is the sign bit,
00:26
and this represents whether or not the number is either positive or negative.
00:30
Then after that, we have the exponents, The exponents says, What power? We're going to raise this number two,
00:35
and then we actually have the number which is called the Mantis. A.
00:40
So, for example, if we have a single precision number, the sign bit is the first bit.
00:46
And then the exponents is the next eight bits, so we can see that they're eight bits here,
00:50
and then the Mantis A is the remaining 23 bits, and that gives us a 32 bit number.
00:57
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
01:11
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.
01:21
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
01:29
and, for example, on X 86 machine, it only has eight stack registers. So S T 01234 all the way up to seven,
01:38
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
01:57
repeat infinitely,
02:00
we have the ability for values to not exactly match up with what we would think of them. When we're talking about decimal
02:08
and then SD zero always points to the top of the stack. So it's a last in first out type of thing
02:15
so floating point operations.
02:19
So, for example, if you want to load something from either memory or
02:23
a register, you can use F L d for floating point load and that a loaded onto the top of the stack
02:30
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.
02:38
You can load the constant one or zero if you need those on top of the stack,
02:45
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.
02:57
And then we have this notion of having the ability to pop. So if you see a command like Fs
03:01
F A S T P, that means it's going to store, do the first part and then pop off the stack. And so
03:09
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.
03:15
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
03:24
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.
03:34
We also have the pop versions
03:37
on each one of these, and then we have. So we have addition, subtraction, multiplication and division.
03:44
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,
03:53
and then let's just give ah, quick example.
03:59
So here I have a simple program.
04:04
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
04:24
so I can go ahead and build it. And I just wanted to run this in that the bugger.
04:29
So I didn't say GTB,
04:30
and then we're gonna break in Assam main,
04:35
and then we'll go ahead and start running. So are for run.
04:40
So I can step through the 1st 2 instructions here.
04:43
So this should load onto the floating point stack.
04:46
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.
04:53
And then I'm going to go ahead and execute this F l D command.
04:59
All right, so it executed that instruction. And if I want again, look at the floating point stack.
05:03
I can see that the number 1.98 or with a bunch of nines and one is stored on there,
05:11
right? And we got our sign bid are Mantis A and then are some bit are exponents that are Mantis A are on there
05:17
and then if we want to look at B to see that it gets saved,
05:23
so I'll examine and then efforts for float and then give it the address of B.
05:29
We can see that it doesn't have anything
05:30
and it looks like a,
05:34
um it's reading the value wrong there. But that's OK,
05:40
so let's do four f the seafood gifts. All right, so we have 1.99
05:46
and so now if we do the next instruction
05:49
and then look at our floating point stack,
05:53
we can see that
05:55
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
06:02
away from where it waas.
06:04
But if we go and look at B
06:10
and I gotta put here four,
06:12
we can see that now I got the value that it was supposed to have. So 1.99
06:21
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.
06:31
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.
06:43
So here's our quiz, but floating point register 20 points to the top of the floating point stack
06:49
S t zero.
06:51
What is the exponent length for a 64 bit floating? Point number?
06:58
11 bits.
07:00
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.
Up Next