Hello, this is Dr. Miller, and this
is Episode eight point four of
Assembly
today, we're going to show some
comparison gone wrong with floating
points and then we're going to give
an example of using floating
point comparisons.
So comparison gone wrong.
So here is a example see program
where we have a floating point
number, so float X,
we go ahead and read that in using
scan F and you can use a percent F,
four percent left
here. And then we're trying to just
compare this to the number one
hundred point one.
And so we're checking for a quality
to see if they're equal and it
should print good if they're equal.
And you can see here that I entered
the number one hundred point one,
which went into that scan F,
but that when it printed it off, it
was one hundred point zero nine nine
nine eight.
And so one of the things we will not
want to do is we don't want to do
direct comparison, because as
you can see, that sometimes
because of the way the floating
point is stored, that it may
go wrong.
And so it's something that we may
not want to do.
So when we're doing floating point
comparisons, some dos and
don'ts. So, again, avoid comparing
for equality and
along that line, either use greater
than or equal to or less than or
equal to if you can.
Right. And so you can try and
trap it with a certain
condition if you want.
But just trying to use greater than
or less than is
is the best way.
And then make sure you read
the right size. So for example,
percent elf is a safe one
to read in any kind of floating
point number, conversions
will will get done for you.
And then if you're using integers,
make sure you use the version of the
floating point command.
So that will help you get
the right value in because that's
an often a mistake that happens.
So we're going to read it, a number
will print it off to make sure it's
right, and then we'll compare it to
a specific value and then we'll have
some statements
that we're going to incorporate.
So I've already got it set up.
So the top will do again as
typical our definition of
some of the strings that we
might need.
So our SCANA format
is going to be postponed,
L.F.
for floating point.
Make sure you put a zero so it knows
what the end of the string is.
We'll have an OK string.
Make sure I terminate my string,
I'll put a new line in, and then
I'll terminate that,
we'll have one called bad.
Again, followed by a new line
and a zero terminated,
and then we're going to have a couple
numbers, 12 X and Y,
and I'm using keywords for that
slide, 64 bits.
And you can pick any number here
that you want.
And then I'm just giving an initial
value to X.
I don't have to do that,
but it makes sure that I'm actually
reading in the value.
So when I print it off, you'll be
able to see that X is
changed from this ninety nine point
nine to something different.
This my print format,
again, you can pick anything you
want, I'll just put a percent
F or float in here.
Terminate my quotes, put a new
line in a zero inside of there,
and then we're going to be using
print F and scan F,
so make sure we declare those as
externals.
All right, so now we're going to
want to scan our number in
so we have to put the pointer on for
where X is.
So we're going to say push X
and we can push the format
for the scan F.
And we can call
scan if and then
we push two things on, so we'll
correct our stack.
Adding eight to E.S.P,
and so now we want to print the
number and so again, it's
going to want sixty four bits on the
stack, so I've got to
push additional data on.
So
move into X, X plus
four. So this gets the top
four bytes.
Push your X,
move X.
Value of X,
push that on in the stacks, I push
to things and then
I push my Pranav format.
And then I'm going to have to
correct the stack by 12, so
I push three things on.
Here we go.
All right, so now I want to do
my comparison here.
So I need to do a floating point
load, I am using a
keyword, so that was the size
that I defined and the value that
I'm getting is X.
Same thing for why
now I'm going to put some comments
here, so X is city
one because it was pushed on, it
started off as T zero, and then
we pushed on Y.
So now why is Estie
zero and
then one user comparison.
So F CompE I
and then P for pop
and we'll compare t zero
to one and
then.
We'll do a just a pop to get rid of
that second number, and so this pops
off one of the numbers, which would
be why this will pop off X so
that our stack is back clean again
and then we can do our jumps.
So jump above.
We'll go to our ecolabel.
So let's define equal.
So here, I'm just going to use the
print strings and move the ax,
OK, I'll
print.
String.
And I'll just jump.
To done so, I'll put a
label down here.
Done.
So we jumped if they were
above, if they are equal and
then we can just do a jump,
unconditional jump.
So if you could do jump less than or
equal to the
jump above, we'll do
the greater. So this will
automatically jump to
and not
above.
We were in the ESX
bad
ball print
string and
then.
All right, so the main part here was
that when we did our COMPAR
put a comment here, let's see.
So
why is
bigger?
And X,
take the
jump.
All right, so if Y is bigger than
X, then we're going to go ahead and
jump because Y is still
zero.
All right, we'll see if I got it
right here.
Oh, right.
Thirty four.
And I think I put an extra letter in
here, they
would go an extra P.
All right.
So if I put one point two,
three, four,
we try to that's equal, right?
And so it won't do that.
It's not above.
But if I do a hundred
or if I do two
or one, so one
is below
one point two, three.
Three is below.
One point two
to three,
three nine
is probably still below, but one
point four is not going to be below.
So today I showed an example
and we did some floating point
comparisons and we learn some of
the sort of do's and don'ts,
making sure that you don't try and
check for quality, because that
is due to the way floating
points are. So it's not going to
work. Right.
So just to make sure that you keep
track of that, when you're trying to
do your comparisons,
looking forward, we're going to have
an example where we try and read in
three numbers and figure out what
the maximum of those is.
And then we'll also start looking at
the arm architecture in future
lectures. And so seeing how that's a
little bit different than the 86
architecture that we've been looking
at.
If you have questions, you can email
me MJM You, Ankita, you,
you and you can find me on Twitter
at Millas 30.