### Video Transcription

00:02

Hello. This is Dr Miller, and this is Episode 8.3 of Assembly.

00:07

Today we're gonna talk about comparing floating point numbers

00:10

and some additional math operations that we have

00:14

so comparing floating point numbers.

00:17

So the F comp instruction allows us to compare two different floating point numbers.

00:23

And then we can use the floating point stack and memory locations in order to do those comparisons.

00:29

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.

00:42

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.

00:58

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.

01:10

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?

01:19

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.

01:36

We also have the f i com,

01:38

and so this will compare

01:41

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,

01:49

um, and pops it off the stack, and then we can use a source which, um, can be a different location.

01:57

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.

02:15

So the flags these above instructions will modify c zero through c three flags on the FP you.

02:23

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.

02:34

And so the F

02:36

STS W will store the flags in a given location. And so, for example, you can,

02:44

um,

02:45

store earthy status into the A X register.

02:49

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

03:08

or use that in your comparison or you jumps.

03:15

So, for example, if you had older hardware, you might load a

03:20

and then compare it to be and then

03:23

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.

03:34

And then you could jump to two somewhere.

03:38

Um, and and that would allow you to do your normal comparison that you would want to do.

03:43

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,

03:55

um, with this eye operation to just directly modify the CPU flags instead of the just the floating point ones.

04:05

And so we have calm I and come I p for the pop version.

04:10

And so

04:12

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,

04:20

and then we can do the pop version.

04:25

So here's some additional math instructions that we have

04:28

so we can do things like change the sign so we can negate a value on the stack or SD zero.

04:35

We can do absolute value,

04:38

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.

04:46

We can do the square root. So take SD zero and do the square root of that.

04:50

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.

05:04

Additionally, we have operations like F Co sign so you can do Floating point co sign

05:12

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

05:28

FBU.

05:30

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.

05:42

So looking forward will go ahead and do an example using floating points and decisions. And so, using jumps

05:47

in that example.

05:50

So here's our quiz. How do you compare two floating point numbers?

05:55

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.

06:08

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

### Up Next

### Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

### Instructed By

Matthew Miller

Instructor