Hello, this is Dr. Miller, and this
is Episode eight point one of
assembly today
we're going to talk about floating
point numbers and then floating
point operations,
floating point numbers.
So a floating point number is
defined and I Tripolis seven
fifty four as
a number for floating point
arithmetic.
And then the very first bit
is the assignment.
And this represents whether or not
the number is either positive or
negative.
And then after that, we have the
exponents, the exponent says, what
power? We're going to raise this
number two.
And then we actually have the
number, which is called the Intesa.
So, for example, if we have a single
precision, no disinhibit is
the first bit and then
the exponent is the next eight
bits. So we can see that there eight
bits here and then the Mentzer
is the remaining twenty three bits
and that gives us a 30 to bit
number.
If we look at a double precision
or a double in the C
programing language, the first bit
is a sign. But again, the exponent
is the next 11 bits and then
the Mentzer is the remaining fifty
two bits.
And so each of these gives us
more 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
FPU has a built in stack
and so it has its own stack that is
separate from the regular stack.
And for example, on an X eighty six
machine, it only has eight
stack registers.
So zero one,
two, three, four, 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'll give us additional precision
that will help and make sure that
it can be more accurate.
And one of the big things to realize
with floating point is that it's not
100 percent accurate.
So because you're still storing
numbers that could repeat
infinitely, 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 estie 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 FMD
for floating point load and
that's loaded onto the top of the
stack and then filed
Satullo load an integer.
And so the eye in here stands for
integer. So it'll take an integer
and then convert it 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, we can
say 40, 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
50 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
integer so we can take a floating
point and copy it to an integer
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 add so zero
plus the source, so I'd add that and
store it on to 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 again, each one has a P variant
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 a quick
example.
So here I have a simple program.
So all it's doing is it has a number
A and A number B, and it's just
using Felda and
TPE, so I'm loading it onto
the floating point stack and then
I'm going to go ahead and store it
back into B, so I would have
A and I would have B.
So I can go ahead and build it and I
just wanted to run this another
bugger
to go ahead and say GDB,
and then we're going to break in
Assen main
and then we'll go ahead and start
running. So our four run
so I can step through the first two
instructions here.
So this should load onto the
floating point stack.
So if I type I for info and then
float it'll show me the floating
point stack and I can see that right
now it has nothing.
And then I'm going to go ahead and
execute this FLD command.
All right, so it executed that
instruction, and if I want to again
look at the floating point stack,
I can see that the number one point
nine eight or with
a bunch of nines and one is stored
on there.
Right. We've got our sign,
Almontaser, and then our sign
that our exponent and then our
mantis are on their.
And then if we want to look at B to
see that it gets saved,
so I'll examine and then F as
her float and then give it the
address of B,
we can see that it doesn't have
anything.
And it looks like A.
It's reading the value wrong there,
but that's OK.
So let's do for
let's see if it gets.
All right. So we have one point nine
nine.
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 zero points to this, so
it actually just leaves it on there
and just moves it away
from where it was.
But if we go and look at B.
And I got to put here for.
We can see that now I got the value
that it was supposed to have, so one
point nine nine.
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.
And we gave some examples.
Looking forward, we're going to do
more complicated floating point
examples and then talk about
floating point decisions.
So selection statements
using floating point.
So here's our quiz.
Floating point registered two points
to the top of the floating point
stack.
Zero,
what is the expert link for a 64
bit floating point number?
Eleven bitz.
If you have questions, you can email
me at millirems, at you and Kadiatu,
Edu, and you can find me on Twitter
at Milhouse 30.