WEBVTT

00:01.080 --> 00:02.579
Hello, this is Dr. Miller, and this

00:02.580 --> 00:04.139
is Episode eight point four of

00:04.140 --> 00:05.140
Assembly

00:06.540 --> 00:08.059
today, we're going to show some

00:08.160 --> 00:09.689
comparison gone wrong with floating

00:09.690 --> 00:10.889
points and then we're going to give

00:10.890 --> 00:12.262
an example of using floating

00:12.810 --> 00:13.859
point comparisons.

00:15.130 --> 00:16.509
So comparison gone wrong.

00:17.350 --> 00:19.810
So here is a example see program

00:19.840 --> 00:21.310
where we have a floating point

00:21.340 --> 00:22.719
number, so float X,

00:23.260 --> 00:25.239
we go ahead and read that in using

00:25.240 --> 00:26.955
scan F and you can use a percent F,

00:27.100 --> 00:28.149
four percent left

00:29.230 --> 00:30.909
here. And then we're trying to just

00:30.910 --> 00:32.380
compare this to the number one

00:32.560 --> 00:33.560
hundred point one.

00:34.770 --> 00:37.029
And so we're checking for a quality

00:37.030 --> 00:38.500
to see if they're equal and it

00:38.740 --> 00:40.299
should print good if they're equal.

00:40.300 --> 00:41.709
And you can see here that I entered

00:41.710 --> 00:43.329
the number one hundred point one,

00:43.360 --> 00:44.799
which went into that scan F,

00:45.460 --> 00:47.139
but that when it printed it off, it

00:47.140 --> 00:48.904
was one hundred point zero nine nine

00:49.150 --> 00:50.150
nine eight.

00:50.800 --> 00:52.719
And so one of the things we will not

00:52.750 --> 00:54.429
want to do is we don't want to do

00:54.430 --> 00:55.851
direct comparison, because as

00:56.380 --> 00:57.910
you can see, that sometimes

00:58.690 --> 01:00.219
because of the way the floating

01:00.220 --> 01:02.259
point is stored, that it may

01:02.260 --> 01:03.039
go wrong.

01:03.040 --> 01:04.089
And so it's something that we may

01:04.090 --> 01:05.090
not want to do.

01:06.010 --> 01:07.359
So when we're doing floating point

01:07.360 --> 01:08.585
comparisons, some dos and

01:09.220 --> 01:11.319
don'ts. So, again, avoid comparing

01:11.320 --> 01:13.239
for equality and

01:13.300 --> 01:14.949
along that line, either use greater

01:14.950 --> 01:16.209
than or equal to or less than or

01:16.210 --> 01:18.099
equal to if you can.

01:18.130 --> 01:20.049
Right. And so you can try and

01:20.050 --> 01:21.999
trap it with a certain

01:22.000 --> 01:23.078
condition if you want.

01:23.230 --> 01:24.789
But just trying to use greater than

01:24.790 --> 01:26.619
or less than is

01:26.620 --> 01:27.489
is the best way.

01:27.490 --> 01:29.409
And then make sure you read

01:29.410 --> 01:30.849
the right size. So for example,

01:30.860 --> 01:32.829
percent elf is a safe one

01:32.830 --> 01:34.689
to read in any kind of floating

01:34.690 --> 01:35.915
point number, conversions

01:36.670 --> 01:38.229
will will get done for you.

01:38.620 --> 01:40.239
And then if you're using integers,

01:40.240 --> 01:41.709
make sure you use the version of the

01:41.710 --> 01:42.879
floating point command.

01:43.570 --> 01:44.795
So that will help you get

01:45.430 --> 01:47.349
the right value in because that's

01:47.350 --> 01:49.000
an often a mistake that happens.

01:50.660 --> 01:51.949
So we're going to read it, a number

01:51.950 --> 01:53.239
will print it off to make sure it's

01:53.240 --> 01:54.769
right, and then we'll compare it to

01:54.770 --> 01:56.449
a specific value and then we'll have

01:56.450 --> 01:57.450
some statements

01:58.370 --> 01:59.869
that we're going to incorporate.

02:02.670 --> 02:03.989
So I've already got it set up.

02:08.530 --> 02:10.629
So the top will do again as

02:10.630 --> 02:11.855
typical our definition of

02:12.460 --> 02:13.783
some of the strings that we

02:14.380 --> 02:15.380
might need.

02:19.190 --> 02:21.440
So our SCANA format

02:21.620 --> 02:24.069
is going to be postponed,

02:24.680 --> 02:25.609
L.F.

02:25.610 --> 02:26.569
for floating point.

02:26.570 --> 02:28.039
Make sure you put a zero so it knows

02:28.040 --> 02:29.250
what the end of the string is.

02:30.080 --> 02:31.490
We'll have an OK string.

02:38.360 --> 02:40.069
Make sure I terminate my string,

02:40.190 --> 02:41.758
I'll put a new line in, and then

02:41.990 --> 02:43.069
I'll terminate that,

02:43.850 --> 02:46.130
we'll have one called bad.

02:50.620 --> 02:52.509
Again, followed by a new line

02:52.510 --> 02:54.129
and a zero terminated,

02:54.700 --> 02:55.599
and then we're going to have a couple

02:55.600 --> 02:57.189
numbers, 12 X and Y,

02:58.750 --> 03:00.269
and I'm using keywords for that

03:00.430 --> 03:01.869
slide, 64 bits.

03:04.090 --> 03:05.379
And you can pick any number here

03:05.380 --> 03:06.339
that you want.

03:06.340 --> 03:07.659
And then I'm just giving an initial

03:07.660 --> 03:08.589
value to X.

03:08.590 --> 03:09.669
I don't have to do that,

03:12.280 --> 03:13.959
but it makes sure that I'm actually

03:13.960 --> 03:14.809
reading in the value.

03:14.810 --> 03:16.119
So when I print it off, you'll be

03:16.120 --> 03:18.009
able to see that X is

03:18.010 --> 03:19.419
changed from this ninety nine point

03:19.420 --> 03:20.740
nine to something different.

03:23.020 --> 03:24.469
This my print format,

03:25.910 --> 03:27.319
again, you can pick anything you

03:27.320 --> 03:29.110
want, I'll just put a percent

03:29.930 --> 03:31.490
F or float in here.

03:33.880 --> 03:35.889
Terminate my quotes, put a new

03:35.890 --> 03:37.900
line in a zero inside of there,

03:39.070 --> 03:40.449
and then we're going to be using

03:40.450 --> 03:41.740
print F and scan F,

03:43.960 --> 03:45.340
so make sure we declare those as

03:45.350 --> 03:46.350
externals.

03:51.100 --> 03:52.668
All right, so now we're going to

03:52.780 --> 03:54.250
want to scan our number in

03:55.360 --> 03:57.124
so we have to put the pointer on for

03:57.340 --> 03:58.219
where X is.

03:58.220 --> 03:59.949
So we're going to say push X

04:00.500 --> 04:02.379
and we can push the format

04:02.380 --> 04:03.380
for the scan F.

04:05.360 --> 04:06.860
And we can call

04:07.850 --> 04:08.850
scan if and then

04:09.770 --> 04:11.089
we push two things on, so we'll

04:11.090 --> 04:12.090
correct our stack.

04:14.040 --> 04:15.449
Adding eight to E.S.P,

04:16.450 --> 04:17.909
and so now we want to print the

04:17.910 --> 04:19.135
number and so again, it's

04:19.769 --> 04:21.299
going to want sixty four bits on the

04:21.300 --> 04:22.499
stack, so I've got to

04:23.250 --> 04:24.426
push additional data on.

04:24.660 --> 04:25.660
So

04:26.760 --> 04:28.979
move into X, X plus

04:28.980 --> 04:30.749
four. So this gets the top

04:30.990 --> 04:31.990
four bytes.

04:33.270 --> 04:34.499
Push your X,

04:35.430 --> 04:37.050
move X.

04:40.280 --> 04:41.519
Value of X,

04:42.150 --> 04:43.816
push that on in the stacks, I push

04:44.070 --> 04:45.889
to things and then

04:45.900 --> 04:47.550
I push my Pranav format.

04:51.630 --> 04:52.529
And then I'm going to have to

04:52.530 --> 04:53.853
correct the stack by 12, so

04:54.420 --> 04:55.649
I push three things on.

05:01.150 --> 05:02.150
Here we go.

05:02.710 --> 05:04.180
All right, so now I want to do

05:04.690 --> 05:05.860
my comparison here.

05:07.220 --> 05:08.899
So I need to do a floating point

05:08.900 --> 05:09.900
load, I am using a

05:10.820 --> 05:12.799
keyword, so that was the size

05:12.800 --> 05:14.417
that I defined and the value that

05:14.540 --> 05:16.039
I'm getting is X.

05:20.180 --> 05:21.649
Same thing for why

05:22.870 --> 05:24.079
now I'm going to put some comments

05:24.080 --> 05:26.350
here, so X is city

05:26.360 --> 05:28.069
one because it was pushed on, it

05:28.070 --> 05:29.589
started off as T zero, and then

05:29.960 --> 05:31.189
we pushed on Y.

05:31.250 --> 05:33.199
So now why is Estie

05:33.320 --> 05:35.239
zero and

05:35.240 --> 05:36.465
then one user comparison.

05:36.470 --> 05:38.399
So F CompE I

05:38.420 --> 05:39.860
and then P for pop

05:40.550 --> 05:42.380
and we'll compare t zero

05:42.710 --> 05:43.710
to one and

05:44.660 --> 05:45.660
then.

05:47.290 --> 05:49.029
We'll do a just a pop to get rid of

05:49.030 --> 05:50.529
that second number, and so this pops

05:50.530 --> 05:51.759
off one of the numbers, which would

05:51.760 --> 05:53.589
be why this will pop off X so

05:53.590 --> 05:55.540
that our stack is back clean again

05:56.590 --> 05:57.769
and then we can do our jumps.

05:57.770 --> 05:59.170
So jump above.

05:59.930 --> 06:01.180
We'll go to our ecolabel.

06:03.240 --> 06:04.920
So let's define equal.

06:08.700 --> 06:09.899
So here, I'm just going to use the

06:09.900 --> 06:11.910
print strings and move the ax,

06:12.870 --> 06:15.000
OK, I'll

06:15.090 --> 06:16.090
print.

06:19.520 --> 06:20.520
String.

06:21.600 --> 06:23.220
And I'll just jump.

06:26.000 --> 06:27.078
To done so, I'll put a

06:27.830 --> 06:29.010
label down here.

06:30.950 --> 06:31.950
Done.

06:33.760 --> 06:35.709
So we jumped if they were

06:35.740 --> 06:37.112
above, if they are equal and

06:37.720 --> 06:39.220
then we can just do a jump,

06:39.530 --> 06:40.709
unconditional jump.

06:40.720 --> 06:43.059
So if you could do jump less than or

06:43.060 --> 06:44.060
equal to the

06:44.920 --> 06:46.089
jump above, we'll do

06:47.020 --> 06:47.949
the greater. So this will

06:47.950 --> 06:49.479
automatically jump to

06:50.050 --> 06:51.050
and not

06:52.480 --> 06:53.559
above.

07:00.740 --> 07:02.669
We were in the ESX

07:03.750 --> 07:04.750
bad

07:05.640 --> 07:07.079
ball print

07:07.980 --> 07:09.850
string and

07:11.900 --> 07:12.900
then.

07:15.380 --> 07:17.299
All right, so the main part here was

07:17.300 --> 07:19.550
that when we did our COMPAR

07:19.850 --> 07:21.589
put a comment here, let's see.

07:23.270 --> 07:24.270
So

07:25.100 --> 07:26.600
why is

07:27.050 --> 07:28.050
bigger?

07:32.930 --> 07:34.039
And X,

07:35.090 --> 07:36.090
take the

07:37.070 --> 07:38.070
jump.

07:39.080 --> 07:40.939
All right, so if Y is bigger than

07:40.940 --> 07:42.019
X, then we're going to go ahead and

07:42.020 --> 07:43.949
jump because Y is still

07:44.070 --> 07:45.070
zero.

07:46.800 --> 07:48.368
All right, we'll see if I got it

07:48.540 --> 07:49.540
right here.

07:51.590 --> 07:52.519
Oh, right.

07:52.520 --> 07:53.660
Thirty four.

07:57.710 --> 07:59.474
And I think I put an extra letter in

07:59.540 --> 08:01.279
here, they

08:01.460 --> 08:03.379
would go an extra P.

08:06.510 --> 08:07.510
All right.

08:09.270 --> 08:10.544
So if I put one point two,

08:11.250 --> 08:12.299
three, four,

08:14.130 --> 08:16.010
we try to that's equal, right?

08:16.020 --> 08:17.660
And so it won't do that.

08:17.670 --> 08:18.670
It's not above.

08:19.410 --> 08:21.209
But if I do a hundred

08:22.200 --> 08:23.610
or if I do two

08:25.050 --> 08:26.939
or one, so one

08:26.940 --> 08:27.940
is below

08:29.070 --> 08:30.099
one point two, three.

08:31.170 --> 08:33.330
Three is below.

08:35.730 --> 08:37.619
One point two

08:38.070 --> 08:39.389
to three,

08:40.080 --> 08:41.149
three nine

08:41.909 --> 08:43.379
is probably still below, but one

08:43.380 --> 08:44.909
point four is not going to be below.

08:51.840 --> 08:53.212
So today I showed an example

08:53.700 --> 08:55.170
and we did some floating point

08:55.320 --> 08:57.210
comparisons and we learn some of

08:57.240 --> 08:58.919
the sort of do's and don'ts,

08:59.640 --> 09:01.306
making sure that you don't try and

09:01.470 --> 09:03.389
check for quality, because that

09:03.390 --> 09:04.664
is due to the way floating

09:05.460 --> 09:06.539
points are. So it's not going to

09:06.540 --> 09:07.540
work. Right.

09:08.010 --> 09:09.599
So just to make sure that you keep

09:09.600 --> 09:10.769
track of that, when you're trying to

09:10.770 --> 09:12.059
do your comparisons,

09:13.350 --> 09:14.519
looking forward, we're going to have

09:14.520 --> 09:16.229
an example where we try and read in

09:16.230 --> 09:17.639
three numbers and figure out what

09:17.640 --> 09:19.559
the maximum of those is.

09:20.130 --> 09:21.839
And then we'll also start looking at

09:21.840 --> 09:23.310
the arm architecture in future

09:23.850 --> 09:25.614
lectures. And so seeing how that's a

09:25.650 --> 09:27.299
little bit different than the 86

09:27.300 --> 09:28.619
architecture that we've been looking

09:28.620 --> 09:29.620
at.

09:30.210 --> 09:31.589
If you have questions, you can email

09:31.590 --> 09:32.766
me MJM You, Ankita, you,

09:33.600 --> 09:35.249
you and you can find me on Twitter

09:35.250 --> 09:36.329
at Millas 30.

