WEBVTT

00:02.320 --> 00:03.909
Hello, this is Dr. Miller, and this

00:03.910 --> 00:05.289
is Episode eight point three of

00:05.290 --> 00:06.290
Assembly today

00:07.420 --> 00:08.889
we're going to talk about comparing

00:08.890 --> 00:10.989
floating point numbers and

00:10.990 --> 00:12.639
some additional math operations that

00:12.640 --> 00:13.640
we have.

00:14.470 --> 00:16.239
So comparing floating point numbers,

00:17.470 --> 00:18.695
so the f comp instruction

00:19.510 --> 00:21.176
allows us to compare two different

00:21.610 --> 00:23.559
floating point numbers and

00:23.560 --> 00:25.239
then we can use the floating point

00:25.240 --> 00:26.514
stack and memory locations

00:27.100 --> 00:28.729
in order to do those comparisons.

00:29.290 --> 00:31.059
And one thing to take into mind when

00:31.060 --> 00:32.726
you're doing this is that floating

00:33.220 --> 00:35.100
point is not an exact science.

00:35.410 --> 00:36.488
So if you do different

00:37.540 --> 00:39.249
operations, you might end up

00:39.580 --> 00:41.019
not being able to compare of two

00:41.020 --> 00:42.020
numbers are equal.

00:42.550 --> 00:43.869
So a lot of times what you'll want

00:43.870 --> 00:45.193
to do is you want to say if

00:45.310 --> 00:46.682
something is greater than or

00:47.140 --> 00:48.609
if something is less than, but not

00:48.610 --> 00:49.982
try and do an exact equality

00:50.890 --> 00:52.630
comparison because

00:52.840 --> 00:54.359
different math operations round

00:54.550 --> 00:56.019
differently. And therefore you might

00:56.020 --> 00:57.280
end up with a different result.

00:59.500 --> 01:01.149
So here we can see that we have the

01:01.150 --> 01:02.228
F. Com, which compares

01:03.580 --> 01:05.469
a source location

01:05.470 --> 01:07.630
and zero, and then it will

01:08.050 --> 01:09.939
set some floating point flags.

01:10.750 --> 01:12.318
We have the pop version with the

01:12.640 --> 01:13.680
P at the end.

01:13.690 --> 01:15.280
And so that will pop off

01:15.640 --> 01:17.319
what's on top of the stack for

01:17.500 --> 01:18.500
T zero.

01:19.900 --> 01:22.239
We have the Compar and

01:22.390 --> 01:24.460
double pop, so you compare

01:24.510 --> 01:26.409
ESTIE zero and S-T one and

01:26.410 --> 01:27.730
then pop the SEC twice.

01:27.740 --> 01:29.169
So if you put two things onto the

01:29.170 --> 01:30.542
stack and you want to remove

01:31.150 --> 01:33.159
them after your operation, you'd use

01:33.160 --> 01:34.360
the double P version.

01:36.780 --> 01:38.819
We also have the F icom,

01:39.870 --> 01:41.879
and so this will compare as

01:41.880 --> 01:44.010
T zero and a source as an integer.

01:44.130 --> 01:45.359
And so we've got the integer

01:45.360 --> 01:46.634
versions, so we've got the

01:47.250 --> 01:49.470
integer version with the P for Pop

01:50.430 --> 01:52.096
and pops it off the stack and then

01:52.200 --> 01:53.909
we can use a source, which

01:54.780 --> 01:56.159
can be a different location.

01:57.120 --> 01:58.680
And then we've got the

01:59.450 --> 02:00.289
highest.

02:00.290 --> 02:02.450
He compares to zero to zero.

02:02.880 --> 02:04.919
So it will just compare at the top

02:04.920 --> 02:06.635
of the stack to the number zero and

02:06.780 --> 02:07.858
check for if something

02:08.699 --> 02:10.109
is zero, which is what we might want

02:10.110 --> 02:11.129
to do a lot of the time.

02:15.160 --> 02:17.409
So the flags, these above

02:17.650 --> 02:18.973
instructions will modify C0

02:20.180 --> 02:21.789
zero through C three flags on the

02:21.790 --> 02:22.790
FPU, but

02:23.650 --> 02:25.209
that means that it's on the floating

02:25.210 --> 02:26.979
point unit and not on the CPU

02:27.160 --> 02:28.900
until you have to copy the bits

02:29.560 --> 02:31.569
of those flags into the CPU in order

02:31.570 --> 02:32.942
to utilize them in your jump

02:33.430 --> 02:34.430
instructions.

02:35.330 --> 02:36.330
And so the F

02:37.490 --> 02:38.490
S.W.

02:38.690 --> 02:40.670
will store the flags

02:40.850 --> 02:42.222
in a given location, and so,

02:42.680 --> 02:44.120
for example, you can

02:45.920 --> 02:47.809
store the status into

02:47.810 --> 02:49.489
the register

02:50.360 --> 02:52.370
and that is probably the easiest one

02:52.730 --> 02:54.889
because then you'll be able to do

02:55.760 --> 02:57.319
the H.F.

02:57.740 --> 02:59.840
So storage to the flags or

02:59.870 --> 03:02.090
load age with the flags.

03:02.480 --> 03:04.048
So probably you want to take and

03:04.190 --> 03:06.499
store what's in H

03:06.500 --> 03:08.215
into the flags register so then you

03:08.240 --> 03:09.318
can modify that or use

03:10.220 --> 03:11.347
that in your comparison

03:12.260 --> 03:13.260
or your jumps.

03:16.100 --> 03:17.717
So, for example, if you had older

03:17.930 --> 03:19.740
hardware, you might load A

03:20.360 --> 03:22.069
and then compare it to B

03:22.460 --> 03:24.319
and then take

03:24.320 --> 03:25.937
the floating point stack and save

03:26.330 --> 03:27.330
it to X and then set

03:28.370 --> 03:30.259
the flags in the general

03:30.500 --> 03:31.500
CPU from X

03:32.360 --> 03:34.026
so it would go ahead and set those

03:34.100 --> 03:35.521
flags and then you could jump

03:35.960 --> 03:37.729
to to somewhere

03:38.660 --> 03:40.375
and that would allow you to do your

03:40.550 --> 03:42.139
normal comparison that you would

03:42.140 --> 03:43.140
want to do.

03:44.070 --> 03:45.419
But what happened was they said that

03:45.420 --> 03:46.939
that was kind of cumbersome and

03:47.280 --> 03:49.080
Pentium two hasn't been around

03:49.500 --> 03:50.500
for a while.

03:50.700 --> 03:51.778
And so for Pentium two

03:52.620 --> 03:54.600
an above, we can basically

03:54.630 --> 03:55.950
do this comparison

03:56.820 --> 03:58.290
with this eye operation

03:58.740 --> 04:00.809
to just directly

04:00.810 --> 04:02.819
modify the CPU flags

04:02.820 --> 04:04.388
instead of the just the floating

04:04.800 --> 04:05.800
point ones.

04:06.180 --> 04:07.356
And so we have Karmi and

04:08.080 --> 04:10.370
come IP for the pop version.

04:10.920 --> 04:13.199
And so the sourcing

04:13.230 --> 04:14.230
on these right.

04:14.430 --> 04:16.078
In this example, it says it must be

04:16.079 --> 04:17.179
on the floating point unit.

04:17.190 --> 04:18.905
So you have to use another floating

04:19.079 --> 04:21.029
point register in order to do that.

04:21.720 --> 04:23.279
And then we can do the pop version.

04:25.190 --> 04:26.779
So here are some additional math

04:26.780 --> 04:27.980
instructions that we have

04:28.670 --> 04:30.619
so we can do things like change

04:30.620 --> 04:32.779
the sign so we can negate

04:32.780 --> 04:35.149
a value on the stack

04:35.150 --> 04:36.150
or zero, we can

04:37.130 --> 04:38.290
do absolute value.

04:38.810 --> 04:40.427
And so you can take and make sure

04:40.520 --> 04:41.809
that if you had a negative number on

04:41.810 --> 04:42.810
there, you could do

04:43.850 --> 04:44.779
absolute value on that.

04:44.780 --> 04:46.519
So you don't have a negative number.

04:47.160 --> 04:48.439
We can do the square root.

04:48.590 --> 04:50.354
So take estie zero and do the square

04:50.420 --> 04:51.420
root of that.

04:51.570 --> 04:53.399
And then there's a scale operation.

04:53.480 --> 04:54.829
So S.T.

04:54.890 --> 04:56.360
zero is going to be zero times

04:57.050 --> 04:58.279
two to the one.

04:58.460 --> 05:00.110
And so that's an easy way to

05:00.830 --> 05:02.360
do a scale operation

05:02.660 --> 05:04.730
using the floating point unit.

05:05.850 --> 05:07.418
Additionally, we have operations

05:08.330 --> 05:09.506
like F cosine so you can

05:10.220 --> 05:11.810
do floating point cosine

05:12.740 --> 05:14.014
f sine floating point sine

05:14.720 --> 05:16.609
and these are operating on T zero

05:16.880 --> 05:17.869
as well as F.P.

05:17.870 --> 05:19.819
10, which will do floating point

05:19.820 --> 05:20.779
tangent.

05:20.780 --> 05:22.309
So if you want to do some math

05:22.310 --> 05:23.437
operations, you can use

05:24.290 --> 05:25.850
those typical math

05:26.210 --> 05:27.679
computations that are built right

05:27.680 --> 05:29.690
into the FPU.

05:31.700 --> 05:33.500
So today, we talked about floating

05:33.770 --> 05:35.689
point comparison and then

05:35.690 --> 05:37.519
some additional math operations

05:37.520 --> 05:39.289
that you might be able to utilize

05:39.290 --> 05:40.730
that are on the floating point unit.

05:42.260 --> 05:43.669
So looking forward, we'll go ahead

05:43.670 --> 05:45.238
and do an example using floating

05:45.740 --> 05:47.357
points and decisions and so using

05:47.870 --> 05:49.910
jumps in that example.

05:51.230 --> 05:52.099
So here's our quiz.

05:52.100 --> 05:53.539
How do you compare to floating point

05:53.540 --> 05:54.540
numbers?

05:55.660 --> 05:57.228
The answer is you can either use

05:57.550 --> 05:58.550
Afkham I or F

05:59.410 --> 06:01.359
Komp and then save the flags

06:01.360 --> 06:03.639
directly from the FPU

06:03.640 --> 06:05.499
into your Flagg's using a sort

06:05.500 --> 06:06.759
of three step operation.

06:08.710 --> 06:10.059
If you have questions, you can email

06:10.060 --> 06:11.060
me at Milgrom, J.R.

06:11.290 --> 06:13.089
Ewing, Keda, Edu, and you can find

06:13.090 --> 06:14.889
me on Twitter at House 30.

