WEBVTT

1
00:01.610 --> 00:03.170
Hello and welcome back.

2
00:03.170 --> 00:06.620
In this lesson, we are going to do a multiple if test.

3
00:07.220 --> 00:09.770
A multiple if test looks like this.

4
00:10.400 --> 00:14.420
There's an if statement, and then inside it there will be two tests.

5
00:14.630 --> 00:20.990
You are testing whether A is larger than B and also whether B is larger than C.

6
00:21.470 --> 00:26.180
If these two conditions are true, then you will assign four to A.

7
00:26.810 --> 00:27.950
Then you end it.

8
00:28.250 --> 00:34.880
So in order to implement this in assembly, we can break it down like this.

9
00:35.150 --> 00:37.790
So we will test whether A is larger than B.

10
00:38.030 --> 00:43.880
If A is not larger than B, then we don't have to test whether B is larger than C.

11
00:44.360 --> 00:45.860
So this is how we do it.

12
00:46.310 --> 00:50.810
First, we move the variable A value into -.

13
00:51.020 --> 00:54.890
Then we move the variable B's value into -.

14
00:54.920 --> 00:58.160
Then we move C's value into -.

15
00:58.700 --> 01:01.460
And then we compare - and -.

16
01:01.550 --> 01:10.280
If - is less than or equal to -, then this condition is false, so it will jump

17
01:11.360 --> 01:14.360
to the endif. That means it will not continue with the second test.

18
01:14.390 --> 01:24.920
However, if A is larger than B, then it will continue with the comparison between - and -.

19
01:28.980 --> 01:37.560
And then if - is larger than C, then the condition will be false, and it will go on to assign four

20
01:37.560 --> 01:39.420
to the variable A.

21
01:39.480 --> 01:47.790
However, if - is not larger than -, then it will jump to the endif over here and it will quit.

22
01:48.600 --> 01:53.820
So the first thing we need to do is to find the addresses that we are going to use for variables A,

23
01:53.850 --> 01:59.250
B, C, and also the address in the text section that we are going to use for endif.

24
01:59.640 --> 02:03.600
So to do that, let us first go to the dump here.

25
02:03.600 --> 02:05.370
Click on it to select it.

26
02:06.740 --> 02:12.920
Then you click on memory map, go to the BSS segment, right-click Follow in dump.

27
02:13.400 --> 02:16.520
Scroll down and look for a location which is empty.

28
02:16.550 --> 02:19.520
Maybe over here. Right-click on this.

29
02:19.520 --> 02:20.780
Copy this address.

30
02:21.860 --> 02:23.180
This will be variable A.

31
02:24.320 --> 02:25.250
Then we paste it there.

32
02:25.490 --> 02:28.010
We are going to assign three to that variable.

33
02:28.010 --> 02:35.480
So come back to this address, right-click, binary edit, and key 03.

34
02:37.190 --> 02:39.770
Next, we look for an address for variable B.

35
02:40.100 --> 02:42.080
So maybe this one will do.

36
02:42.380 --> 02:47.810
Right-click, copy address, and then paste it in here.

37
02:48.590 --> 02:50.750
And we assign two to this variable.

38
02:50.750 --> 02:58.490
So let's come back here and right-click, select binary edit, and key in 02.

39
03:00.660 --> 03:03.360
Next, we look for an address for variable C.

40
03:03.990 --> 03:05.280
Maybe this one.

41
03:05.280 --> 03:10.770
Right-click, copy address, and paste it in here.

42
03:12.610 --> 03:15.970
And we are going to assign one to this address.

43
03:15.970 --> 03:23.770
So come back here, right-click, binary edit, and key in 01.

44
03:25.150 --> 03:27.670
So now we have got our three variables.

45
03:28.030 --> 03:32.620
And we have also initialized them with the values three, two, and one.

46
03:33.310 --> 03:40.270
Next, we need to look for the address for the endif that we are going to use in the text segment.

47
03:41.260 --> 03:44.950
So the text segment, we scroll down to the bottom and maybe pick this one.

48
03:45.100 --> 03:46.600
Right-click the address.

49
03:46.600 --> 03:49.330
Copy the address.

50
03:52.250 --> 03:54.140
And paste it in here.

51
03:56.720 --> 03:58.640
Now we have all our addresses.

52
03:58.640 --> 04:00.080
We can start coding.

53
04:00.500 --> 04:04.670
So let's go and code all this over here.

54
04:05.480 --> 04:08.030
Put the breakpoint there and then start keying in your code.

55
04:09.830 --> 04:11.420
MOV -.

56
04:16.250 --> 04:19.700
And then copy your address for variable A.

57
04:23.090 --> 04:24.830
And paste it in here.

58
04:28.780 --> 04:31.240
Next will be MOV -.

59
04:40.110 --> 04:43.200
Copy the address for variable B.

60
04:48.390 --> 04:49.770
And paste it here.

61
04:52.450 --> 04:54.490
Next will be to move -.

62
05:03.770 --> 05:06.170
Copy the address for C.

63
05:10.070 --> 05:11.930
And paste it here.

64
05:16.080 --> 05:20.160
Next will be the compare - with -.

65
05:27.380 --> 05:30.410
Followed by jump less or equal to.

66
05:33.170 --> 05:36.410
Then we copy the address of endif.

67
05:41.900 --> 05:43.640
And paste it in here.

68
05:45.680 --> 05:48.680
Next, we will compare - with -.

69
05:57.220 --> 05:59.860
And then we'll do jump less or equal to

70
05:59.860 --> 06:00.460
endif.

71
06:04.970 --> 06:07.820
Copy the address for endif from here.

72
06:09.920 --> 06:11.390
And paste it in here.

73
06:14.110 --> 06:17.410
Finally, we will move four to variable A.

74
06:23.210 --> 06:25.250
Copy the address of variable A.

75
06:30.530 --> 06:32.270
And paste it in here.

76
06:37.100 --> 06:37.970
Type four.

77
06:43.760 --> 06:47.120
Now we need to check, make sure we have entered correctly.

78
06:47.780 --> 06:49.190
So let's check.

79
06:49.310 --> 06:56.240
This is -, 0x407000, which is variable A, 0x407000.

80
06:56.420 --> 07:01.610
Next one is -, 0x407020, which is variable B.

81
07:01.610 --> 07:08.360
Next is -, which is 0x407100.

82
07:08.360 --> 07:12.380
Next is compare - with -.

83
07:12.380 --> 07:13.730
Next is jump

84
07:14.640 --> 07:17.070
to jump less or equal to endif.

85
07:17.460 --> 07:20.850
Endif would be this address, 0x4015B9.

86
07:21.000 --> 07:30.450
Next would be compare - with -, then jump less or equal to endif again, which is 0x4015B9, and

87
07:30.450 --> 07:33.960
finally move four to variable A.

88
07:33.990 --> 07:37.440
So variable A is 0x407000.

89
07:37.950 --> 07:40.830
So now we can run to our breakpoint.

90
07:41.580 --> 07:50.580
Step over, it moves variable A to -. Variable A is three, so it's three now.

91
07:50.790 --> 07:56.700
Then it moves variable B, which is two, into -.

92
07:56.730 --> 08:01.470
Next, it moves variable C, which is one, into -.

93
08:01.740 --> 08:03.270
So we have three, two, one.

94
08:03.750 --> 08:06.090
Next, we compare variable A and B.

95
08:07.020 --> 08:09.780
We compare register A and B, which is three and two.

96
08:09.810 --> 08:11.310
So it's bigger than two.

97
08:11.700 --> 08:15.390
So yes, it is, so it will not jump.

98
08:16.140 --> 08:20.370
As you can see, the arrow is grayed out and jump is not taken.

99
08:20.370 --> 08:21.870
So we step over.

100
08:21.870 --> 08:23.310
We go to the next line.

101
08:24.150 --> 08:28.230
We compare - with -. - is two, bigger than one?

102
08:28.230 --> 08:29.280
So we step over.

103
08:30.030 --> 08:31.440
Yes, it is bigger than one.

104
08:31.440 --> 08:33.600
So this jump will not jump.

105
08:33.840 --> 08:39.540
As you can see again, the arrow is grayed out and jump is not taken.

106
08:39.540 --> 08:40.470
It's shown here.

107
08:41.070 --> 08:47.400
So it's going to go straight and assign four to variable A.

108
08:47.400 --> 08:48.360
So let's step over.

109
08:48.360 --> 08:51.960
And you see now four has been assigned to variable A.

110
08:52.890 --> 08:57.720
So this is how you can implement multiple if tests inside assembly language.

111
08:57.720 --> 08:59.010
Thank you for watching.