13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 8.3 of Assembly.
Today we're gonna 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 if two numbers are equal.
So a lot of times, what you 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 results.
So here we can see that we have the F com, which compares a source location and S t 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 S t zero?
We have the compare and double pop, so you compare s t zero in S t one and then pop the sack 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 i com,
and so this will compare
as t zero and a source as an imager. And so we got the energy versions. So we got the energy version with the p for pop,
um, and pops it off the stack, and then we can use a source which, um, can be a different location.
And then we've got the f i S t compares s t 0 to 0. So it will just compare at the top of the stack to the number zero and check for, um 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 c zero through c three flags on the FP you.
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
STS W will store the flags in a given location. And so, for example, you can,
store earthy status into the A X register.
Um, and that is probably the easiest one, because then you'll be able to do, um, the essay H f so store age to the flags or load H with the flags. So probably you want to take in store what's in a H into the flags registers, and then you can modify that
or use that in your comparison or you jumps.
So, for example, if you had older hardware, you might load a
and then compare it to be and then
take the floating point stack and save it to a X, and then set the flags in the general CPU from a X so it would go ahead and set those flags.
And then you could jump to two somewhere.
Um, and 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 and above, we can basically do these comparison,
um, with this eye operation to just directly modify the CPU flags instead of the just the floating point ones.
And so we have calm I and come I p for the pop version.
the source in Anne's 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's 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 SD 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 SD zero and do the square root of that.
And then there's a scale operation. So S T zero is going to be S t zero times two to the F t one, and so that's an easy way to do a scale operation using the floating point unit.
Additionally, we have operations like F Co sign so you can do Floating point co sign
F sign floating point sign and these air operating honesty zero, as well as FB Tan, which will do floating point tangent. So if you want to do some math operations, you can use those typical math computations. They're built right into the
So today we talked about floating point comparison and then some additional math operations you might be able to utilize that are on the floating point unit.
So looking forward will 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 two floating point numbers?
The answer is, you can either use F calm I or F comp and then save the flags directly from the FBU into your flags, using a sort of three step operation.
If you have questions, you can email me at Miller MJ at you and Kate, I e. T you and you can find me on Twitter at Milhouse 30