Hello and welcome back.
In this lesson, we are going to study DIV.
DIV stands for divide.
So let's take a look at what is the meaning of DIV.
So in this case here, the number that we want to divide is stored in the - and - register.
So we need to store in this way - -.
So what this means is that - and - registers are combined to form a 128-bit dividend.
The DIV instruction then divides this 128-bit value by the specified operand.
For example, a register.
So the result of the division can be a quotient and the remainder.
So the quotient will be placed in the - register and the remainder will be placed in the - register.
So - - divided by register gives you the quotient which is placed in - and - - modulus will
give you the remainder.
There are also exceptions that can occur if you divide with zero.
For example, if your divisor is zero, then you will result in an exception.
Another exception is where the number that you divide is very big, but the divisor is very small.
Then the result will not be able to fit into the quotient, so it causes an integer overflow.
So let's take a look at this in the x64dbg.
I have opened my template 2X.
Now let's try to divide five with two.
So let's move.
Let's set our - to be zero.
And then we move - five, and then we divide.
Then we move.
Uh, - two.
So in this case here.
We need to set it to zero because we want to.
Because when you divide, it's going to combine the - and - register.
So let's start over now.
Let's run to our breakpoint.
So it is zero.
- is zero.
And then now - is five.
So we are going to divide - combined with -.
So that's why we need to set - to be zero.
Then we are going to divide it with - which is two.
So let's step over.
And now - is two.
Now we need to perform the division with -.
So after dividing, we get the result in the -.
And -.
So - is your quotient and your - is one, just as expected.
Now, the exception that occurs if we divide with zero or divide with a big number.
Let's try a big number.
So let's say we move.
So they are all together here.
A QWORD here.
I just type in 16 F's, so it's a QWORD there.
Very big number.
And also do the same thing with -.
So now it's a huge number and we are going to divide it with two.
Let's do a division now.
Let's step over.
So it moves this into - and it moves this into -.
So now the number that we're dividing is - combined with -.
So it becomes a very long number or very big.
And then you're going to divide with two.
So if you step over, you will see there's an exception mentioned here.
Exception integer overflow.
Because the result of the division is too big to fit into -.
That's why it overflows.
So this is how you can implement division inside the x64dbg assembly.
That's all for this video.
Thank you for watching.