WEBVTT

1
00:01.690 --> 00:03.010
Hello and welcome back.

2
00:03.010 --> 00:05.200
In this lesson, we are going to study DIV.

3
00:05.830 --> 00:07.330
DIV stands for divide.

4
00:08.290 --> 00:11.770
So let's take a look at what is the meaning of DIV.

5
00:12.250 --> 00:21.310
So in this case here, the number that we want to divide is stored in the - and - register.

6
00:22.150 --> 00:25.960
So we need to store in this way - -.

7
00:26.110 --> 00:33.940
So what this means is that - and - registers are combined to form a 128-bit dividend.

8
00:34.450 --> 00:39.520
The DIV instruction then divides this 128-bit value by the specified operand.

9
00:40.300 --> 00:42.010
For example, a register.

10
00:42.640 --> 00:47.770
So the result of the division can be a quotient and the remainder.

11
00:47.770 --> 00:55.930
So the quotient will be placed in the - register and the remainder will be placed in the - register.

12
00:56.830 --> 01:07.090
So - - divided by register gives you the quotient which is placed in - and - - modulus will

13
01:07.090 --> 01:08.260
give you the remainder.

14
01:08.590 --> 01:13.150
There are also exceptions that can occur if you divide with zero.

15
01:13.180 --> 01:19.060
For example, if your divisor is zero, then you will result in an exception.

16
01:19.630 --> 01:25.390
Another exception is where the number that you divide is very big, but the divisor is very small.

17
01:25.600 --> 01:32.680
Then the result will not be able to fit into the quotient, so it causes an integer overflow.

18
01:33.280 --> 01:37.030
So let's take a look at this in the x64dbg.

19
01:37.630 --> 01:39.640
I have opened my template 2X.

20
01:40.180 --> 01:43.570
Now let's try to divide five with two.

21
01:44.780 --> 01:47.210
So let's move.

22
01:51.110 --> 01:53.030
Let's set our - to be zero.

23
01:56.680 --> 02:03.520
And then we move - five, and then we divide.

24
02:03.580 --> 02:04.720
Then we move.

25
02:04.720 --> 02:07.900
Uh, - two.

26
02:09.400 --> 02:11.050
So in this case here.

27
02:11.760 --> 02:15.630
We need to set it to zero because we want to.

28
02:15.630 --> 02:20.040
Because when you divide, it's going to combine the - and - register.

29
02:20.190 --> 02:21.900
So let's start over now.

30
02:21.930 --> 02:23.400
Let's run to our breakpoint.

31
02:25.220 --> 02:26.870
So it is zero.

32
02:28.530 --> 02:29.790
- is zero.

33
02:30.180 --> 02:33.120
And then now - is five.

34
02:33.420 --> 02:39.840
So we are going to divide - combined with -.

35
02:40.140 --> 02:42.960
So that's why we need to set - to be zero.

36
02:43.590 --> 02:47.820
Then we are going to divide it with - which is two.

37
02:47.850 --> 02:48.960
So let's step over.

38
02:49.590 --> 02:51.510
And now - is two.

39
02:52.620 --> 02:56.550
Now we need to perform the division with -.

40
03:00.070 --> 03:05.020
So after dividing, we get the result in the -.

41
03:06.260 --> 03:07.190
And -.

42
03:07.190 --> 03:13.220
So - is your quotient and your - is one, just as expected.

43
03:13.910 --> 03:18.710
Now, the exception that occurs if we divide with zero or divide with a big number.

44
03:18.710 --> 03:20.420
Let's try a big number.

45
03:21.170 --> 03:23.210
So let's say we move.

46
03:30.580 --> 03:33.550
So they are all together here.

47
03:33.550 --> 03:34.660
A QWORD here.

48
03:34.810 --> 03:38.680
I just type in 16 F's, so it's a QWORD there.

49
03:38.710 --> 03:39.640
Very big number.

50
03:40.360 --> 03:44.290
And also do the same thing with -.

51
03:51.140 --> 03:56.450
So now it's a huge number and we are going to divide it with two.

52
03:57.050 --> 03:58.430
Let's do a division now.

53
04:02.220 --> 04:03.270
Let's step over.

54
04:05.150 --> 04:11.030
So it moves this into - and it moves this into -.

55
04:11.030 --> 04:14.780
So now the number that we're dividing is - combined with -.

56
04:14.900 --> 04:17.810
So it becomes a very long number or very big.

57
04:17.960 --> 04:21.020
And then you're going to divide with two.

58
04:21.470 --> 04:24.920
So if you step over, you will see there's an exception mentioned here.

59
04:25.340 --> 04:26.990
Exception integer overflow.

60
04:27.410 --> 04:32.150
Because the result of the division is too big to fit into -.

61
04:32.180 --> 04:33.230
That's why it overflows.

62
04:33.770 --> 04:40.580
So this is how you can implement division inside the x64dbg assembly.

63
04:40.610 --> 04:42.050
That's all for this video.

64
04:42.050 --> 04:43.310
Thank you for watching.