WEBVTT

1
00:01.730 --> 00:03.440
Hello and welcome back.

2
00:03.440 --> 00:09.350
In this lesson, we are going to take a look at the practical for the XOR operations.

3
00:09.350 --> 00:14.630
And the syntax for XOR operation is: XOR destination, source.

4
00:14.810 --> 00:17.150
And these are two examples.

5
00:17.810 --> 00:25.520
So first, let's put the breakpoint in our template file, which is template 2x, at this location.

6
00:25.970 --> 00:29.750
And then we'll run and hit our breakpoint,

7
00:29.750 --> 00:33.350
and we step over until we come to this line.

8
00:33.620 --> 00:41.960
So here is where we are going to move our initial value to the - register.

9
00:42.860 --> 00:45.020
So we use -.

10
00:45.110 --> 00:49.040
And let's type a move here.

11
00:53.350 --> 00:54.220
Move -,

12
00:56.830 --> 01:00.340
12345678.

13
01:01.090 --> 01:01.420
Okay.

14
01:01.420 --> 01:04.510
Let's say we put this in the - register.

15
01:07.880 --> 01:10.940
So this is the value you want to put to register.

16
01:16.600 --> 01:18.940
I just copy and paste here so you have a copy.

17
01:19.720 --> 01:20.650
Hit okay.

18
01:22.420 --> 01:27.910
And now we step over, and now B3 is in - register.

19
01:27.910 --> 01:29.680
So this is B3 in hex.

20
01:29.830 --> 01:33.010
And we can confirm that with our calculator.

21
01:36.560 --> 01:39.200
Go to hex and type B3.

22
01:44.720 --> 01:47.090
And we see this value here.

23
01:47.630 --> 01:48.260
Same.

24
01:50.340 --> 01:53.340
Now we are going to do something unique.

25
01:53.370 --> 01:56.340
We are going to XOR - with itself.

26
01:58.970 --> 02:01.640
So XOR - with -.

27
02:02.990 --> 02:04.160
See what happens.

28
02:07.170 --> 02:10.860
So we are referring to the second one here, XOR with itself.

29
02:11.280 --> 02:14.160
So when we run this, watch what happens to this.

30
02:15.720 --> 02:16.920
It becomes zero.

31
02:16.920 --> 02:20.760
So this is a very special characteristic of XOR.

32
02:21.030 --> 02:26.190
When you XOR any register with itself, you zero out the register.

33
02:26.310 --> 02:32.610
Now this is very often used in the assembly code because it is more efficient than moving zero to the

34
02:32.610 --> 02:33.330
register.

35
02:33.810 --> 02:35.490
It consumes less bytes.

36
02:36.510 --> 02:39.030
So take note of that.

37
02:39.600 --> 02:42.120
Now, let's do something else.

38
02:42.420 --> 02:48.090
Let's move back this value into the - register.

39
02:58.890 --> 02:59.520
Step over.

40
03:00.840 --> 03:02.580
And now we get back our B3.

41
03:02.580 --> 03:06.480
So now we are going to do another something else which is rather unique.

42
03:06.480 --> 03:11.250
We are going to XOR the register with all ones.

43
03:13.450 --> 03:16.300
So XOR - with all ones.

44
03:19.910 --> 03:22.220
So there are eight bits here of one.

45
03:22.400 --> 03:23.000
Eight ones.

46
03:24.490 --> 03:24.730
Okay.

47
03:26.650 --> 03:30.550
Okay, so we are going to XOR with all ones.

48
03:31.630 --> 03:32.620
Let me check that.

49
03:33.160 --> 03:35.740
Sorry, this should be 0b.

50
03:38.490 --> 03:38.880
All right.

51
03:38.880 --> 03:43.260
So when you convert all ones to hex, it is FF.

52
03:43.710 --> 03:46.350
So let's try this and see what happens.

53
03:46.350 --> 03:47.370
This is the original bit.

54
03:47.370 --> 03:50.040
And now we are going to XOR it with all ones.

55
03:52.140 --> 03:53.220
And we get 4C.

56
03:53.430 --> 03:57.330
So what is 4C in binary?

57
03:57.330 --> 03:59.100
So let's open a calculator.

58
04:01.630 --> 04:08.260
So we can go to hex first. Type 4C.

59
04:09.370 --> 04:13.510
And we see that it is 01001100.

60
04:14.350 --> 04:15.550
This value here.

61
04:16.990 --> 04:18.850
Now what is the significance of that?

62
04:18.850 --> 04:19.330
Take a look.

63
04:19.360 --> 04:21.040
We copy and paste it here.

64
04:28.390 --> 04:32.800
Notice every bit in the original number has been flipped.

65
04:32.800 --> 04:34.630
So one became zero.

66
04:34.810 --> 04:36.220
Zero became one.

67
04:36.760 --> 04:37.180
See that?

68
04:39.460 --> 04:45.190
So there is a significance of XORing any number with all ones.

69
04:45.340 --> 04:47.380
The effect is to flip all the bits.

70
04:48.190 --> 04:48.580
Okay.

71
04:48.580 --> 04:55.030
So this is an example of the register and immediate, and register and register, and also some

72
04:55.030 --> 05:00.820
characteristics of XOR: register with itself, and also XOR of register with all ones.

73
05:00.970 --> 05:02.710
So that's all for this video.

74
05:02.740 --> 05:04.420
Thank you for watching.