Hello, this is Dr. Miller, and this
is Episode eight point three of
Assembly today
we're going to talk about comparing
floating point numbers and
some additional math operations that
we have.
So comparing floating point numbers,
so the f comp instruction
allows us to compare two different
floating point numbers and
then we can use the floating point
stack and memory locations
in order to do those comparisons.
And one thing to take into mind when
you're doing this is that floating
point is not an exact science.
So if you do different
operations, you might end up
not being able to compare of two
numbers are equal.
So a lot of times what you'll want
to do is you want to say if
something is greater than or
if something is less than, but not
try and do an exact equality
comparison because
different math operations round
differently. And therefore you might
end up with a different result.
So here we can see that we have the
F. Com, which compares
a source location
and zero, and then it will
set some floating point flags.
We have the pop version with the
P at the end.
And so that will pop off
what's on top of the stack for
T zero.
We have the Compar and
double pop, so you compare
ESTIE zero and S-T one and
then pop the SEC twice.
So if you put two things onto the
stack and you want to remove
them after your operation, you'd use
the double P version.
We also have the F icom,
and so this will compare as
T zero and a source as an integer.
And so we've got the integer
versions, so we've got the
integer version with the P for Pop
and pops it off the stack and then
we can use a source, which
can be a different location.
And then we've got the
highest.
He compares to zero to zero.
So it will just compare at the top
of the stack to the number zero and
check for if something
is zero, which is what we might want
to do a lot of the time.
So the flags, these above
instructions will modify C0
zero through C three flags on the
FPU, but
that means that it's on the floating
point unit and not on the CPU
until you have to copy the bits
of those flags into the CPU in order
to utilize them in your jump
instructions.
And so the F
S.W.
will store the flags
in a given location, and so,
for example, you can
store the status into
the register
and that is probably the easiest one
because then you'll be able to do
the H.F.
So storage to the flags or
load age with the flags.
So probably you want to take and
store what's in H
into the flags register so then you
can modify that or use
that in your comparison
or your jumps.
So, for example, if you had older
hardware, you might load A
and then compare it to B
and then take
the floating point stack and save
it to X and then set
the flags in the general
CPU from X
so it would go ahead and set those
flags and then you could jump
to to somewhere
and that would allow you to do your
normal comparison that you would
want to do.
But what happened was they said that
that was kind of cumbersome and
Pentium two hasn't been around
for a while.
And so for Pentium two
an above, we can basically
do this comparison
with this eye operation
to just directly
modify the CPU flags
instead of the just the floating
point ones.
And so we have Karmi and
come IP for the pop version.
And so the sourcing
on these right.
In this example, it says it must be
on the floating point unit.
So you have to use another floating
point register in order to do that.
And then we can do the pop version.
So here are some additional math
instructions that we have
so we can do things like change
the sign so we can negate
a value on the stack
or zero, we can
do absolute value.
And so you can take and make sure
that if you had a negative number on
there, you could do
absolute value on that.
So you don't have a negative number.
We can do the square root.
So take estie zero and do the square
root of that.
And then there's a scale operation.
So S.T.
zero is going to be zero times
two to the one.
And so that's an easy way to
do a scale operation
using the floating point unit.
Additionally, we have operations
like F cosine so you can
do floating point cosine
f sine floating point sine
and these are operating on T zero
as well as F.P.
10, which will do floating point
tangent.
So if you want to do some math
operations, you can use
those typical math
computations that are built right
into the FPU.
So today, we talked about floating
point comparison and then
some additional math operations
that you might be able to utilize
that are on the floating point unit.
So looking forward, we'll go ahead
and do an example using floating
points and decisions and so using
jumps in that example.
So here's our quiz.
How do you compare to floating point
numbers?
The answer is you can either use
Afkham I or F
Komp and then save the flags
directly from the FPU
into your Flagg's using a sort
of three step operation.
If you have questions, you can email
me at Milgrom, J.R.
Ewing, Keda, Edu, and you can find
me on Twitter at House 30.