WEBVTT

1
00:01.100 --> 00:02.630
Hello and welcome back.

2
00:02.630 --> 00:05.630
In this lesson, we are going to study the carry flag.

3
00:05.630 --> 00:11.450
-, so let's try to put some value in -.

4
00:11.480 --> 00:14.360
Before that, let us run to our breakpoint.

5
00:14.570 --> 00:16.100
We are using template two.

6
00:16.370 --> 00:18.350
Step over until you reach this line.

7
00:18.740 --> 00:22.670
So let's try to perform an operation using -.

8
00:22.760 --> 00:32.810
That means the first byte. Right-click on the - register, modify, and set it to ten in hex.

9
00:34.310 --> 00:37.400
So now we are going to perform an arithmetic operation.

10
00:37.400 --> 00:39.020
We are going to add one to -.

11
00:41.260 --> 00:42.970
Add -, one.

12
00:44.860 --> 00:46.510
So notice the carry flag.

13
00:46.540 --> 00:51.790
Carry flag should not be set because the size of the

14
00:51.790 --> 00:55.120
- is a maximum size, 255.

15
00:55.120 --> 01:00.040
So it should be able to store the value of the operation.

16
01:00.040 --> 01:01.600
So let's step over this,

17
01:01.600 --> 01:04.870
and you notice that the - flag is not set.

18
01:05.020 --> 01:07.540
So you managed to increase it by one.

19
01:07.540 --> 01:08.380
So it's 11.

20
01:08.380 --> 01:12.160
So maximum is 255. 255 in hex is FF.

21
01:12.490 --> 01:14.620
So in this case, it doesn't exceed FF.

22
01:14.650 --> 01:16.840
Therefore, the carry flag is not set.

23
01:17.350 --> 01:22.750
So now let's try to perform an operation which will increase the value beyond 255.

24
01:22.840 --> 01:28.120
So let's try to add -, 255 itself.

25
01:29.440 --> 01:32.740
So now you're going to add this FF with this 255.

26
01:32.860 --> 01:39.700
And you step over, and you see now the carry flag is set because the size of the - register is too small

27
01:39.700 --> 01:42.400
to store the result of the addition.

28
01:42.400 --> 01:47.020
That's why you see carry flag is set, indicating that there is an error.

29
01:48.220 --> 01:48.580
Okay.

30
01:48.580 --> 01:51.220
Now let's study the subtraction.

31
01:52.060 --> 01:54.430
For that, we will use the - register.

32
01:54.430 --> 01:57.190
- register now is one.

33
01:57.190 --> 02:00.370
Let's try to subtract one from it.

34
02:00.550 --> 02:09.130
So let's subtract -, one, and see what happens.

35
02:09.130 --> 02:10.150
Step over that,

36
02:10.150 --> 02:16.990
and you see carry flag is cleared because the size of the register is sufficient for doing the

37
02:16.990 --> 02:17.920
subtraction.

38
02:18.310 --> 02:23.410
So now let's try to minus another big number from -, see what happens.

39
02:25.150 --> 02:28.480
Subtract, maybe minus ten from -.

40
02:30.250 --> 02:31.720
And we step over, you see,

41
02:31.750 --> 02:32.770
carry flag is set.

42
02:32.950 --> 02:38.680
This is because the - flag only captures the unsigned numbers

43
02:39.100 --> 02:39.670
operation.

44
02:39.670 --> 02:42.310
So in this case, it cannot store negative numbers.

45
02:42.340 --> 02:46.210
- only captures the error for unsigned numbers.

46
02:46.300 --> 02:51.910
So because when you minus one from zero, it is already a negative number.

47
02:51.910 --> 02:55.810
So negative number cannot be stored in the - register.

48
02:55.810 --> 02:59.620
That's why it shows as a carry flag set to one.

49
03:00.040 --> 03:06.880
So that's how the - flag is used in the assembly.

50
03:06.880 --> 03:08.560
So that's all for this video.

51
03:08.560 --> 03:09.760
Thank you for watching.