WEBVTT

1
00:00.860 --> 00:02.210
Hello and welcome back.

2
00:02.210 --> 00:06.410
This time we are going to do a function call with seven arguments.

3
00:06.410 --> 00:09.740
So again, try to pause this video and try on your own.

4
00:09.770 --> 00:11.090
See if you can do it.

5
00:11.090 --> 00:15.410
And this time try to create local variables and try to make use of them as well.

6
00:15.410 --> 00:16.790
And good luck.

7
00:18.820 --> 00:19.240
All right.

8
00:19.240 --> 00:21.100
So this is how we are going to do it.

9
00:21.100 --> 00:24.760
We are going to reload our template as usual,

10
00:24.760 --> 00:30.010
our template. We are going to create the seven arguments.

11
00:30.130 --> 00:37.990
So the first one we are going to move - one.

12
00:38.800 --> 00:51.010
Second one is -, two. Third one is -, which is three. Fourth one is -, which is four.

13
00:51.490 --> 00:56.380
And now we have to allocate space for

14
00:57.590 --> 00:59.840
the variables, the arguments.

15
01:00.170 --> 01:11.780
So the fifth, sixth and seventh, fifth, six and seven, five, six and seven arguments.

16
01:14.420 --> 01:15.320
How many bytes?

17
01:16.130 --> 01:16.760
24.

18
01:16.760 --> 01:16.970
Why?

19
01:17.000 --> 01:17.360
Because

20
01:17.360 --> 01:18.200
three times eight.

21
01:19.950 --> 01:20.940
We take three

22
01:22.620 --> 01:24.180
times eight.

23
01:24.600 --> 01:29.550
So that gives you 24 bytes, five, six and seven.

24
01:29.550 --> 01:34.620
So 24 plus 32, 56 here, 56 bytes.

25
01:34.620 --> 01:35.550
So total,

26
01:37.760 --> 01:41.120
total is 32 plus 24.

27
01:41.570 --> 01:43.340
That will give you 56.

28
01:44.930 --> 01:47.840
So here we need to sub -.

29
01:50.620 --> 01:51.490
56.

30
01:51.610 --> 01:55.030
So 56 in hex is 38.

31
01:55.630 --> 02:01.570
Now we can start to, uh, assign variables to the five, six and seven.

32
02:01.780 --> 02:09.010
So to do that, we use the offset - plus 32, - plus 40, and - plus 48.

33
02:09.460 --> 02:13.090
So fifth variable, move

34
02:14.900 --> 02:17.210
- plus 32.

35
02:19.560 --> 02:20.940
Move the fifth argument there.

36
02:27.280 --> 02:31.660
- plus 40, sixth argument.

37
02:35.860 --> 02:37.150
- plus 48

38
02:39.710 --> 02:40.910
for the seventh argument.

39
02:41.570 --> 02:42.350
Done.

40
02:43.220 --> 02:43.910
Done.

41
02:44.270 --> 02:45.980
Now we need a function call.

42
02:46.010 --> 02:48.080
Maybe we choose somewhere down here.

43
02:48.230 --> 02:48.890
Don't worry.

44
02:48.890 --> 02:50.330
We can just overwrite all this.

45
02:50.870 --> 02:52.190
We can actually

46
02:52.190 --> 02:52.640
NOP

47
02:52.640 --> 02:53.360
all this up.

48
02:53.360 --> 02:54.830
Give us more space.

49
02:55.010 --> 02:57.080
So let's select all this to NOP.

50
02:58.820 --> 03:00.170
Binary fill NOPs.

51
03:00.170 --> 03:02.120
Then we get more space to do our code.

52
03:02.960 --> 03:03.320
All right.

53
03:03.320 --> 03:05.570
So we got some space now to write our code.

54
03:05.780 --> 03:09.860
So we choose something down here for our function, okay.

55
03:09.860 --> 03:15.830
So our function call, let's say we choose a location somewhere down here.

56
03:16.770 --> 03:16.950
Okay.

57
03:17.460 --> 03:19.020
Copy that address.

58
03:20.400 --> 03:22.140
You come here and make our call.

59
03:25.840 --> 03:28.150
Call, paste the address.

60
03:31.160 --> 03:33.080
When you come back, you must clean.

61
03:33.080 --> 03:36.470
So you do an add -.

62
03:36.860 --> 03:40.610
And here we need to clean 56 bytes.

63
03:46.560 --> 03:47.310
Then

64
03:47.310 --> 03:49.920
the result will be in -.

65
03:50.130 --> 03:52.200
You can store it in - if you want.

66
03:52.200 --> 03:53.370
So let's do that.

67
03:54.990 --> 03:58.230
Move to - the result of the addition.

68
04:00.310 --> 04:00.970
There you go.

69
04:02.020 --> 04:02.410
Right.

70
04:02.410 --> 04:06.130
So now it will call this function 401 5B4.

71
04:06.550 --> 04:11.860
So here we implement a function, push -.

72
04:17.960 --> 04:20.300
Move - -.

73
04:21.320 --> 04:26.090
Then we create four local variables.

74
04:26.090 --> 04:31.640
So we sub the - 32, 32 bytes here.

75
04:32.360 --> 04:38.360
Now we try to move all our arguments to the local variable for exercise.

76
04:38.660 --> 04:46.310
Let's move all our arguments, the first four arguments to our local variable, - minus eight, - minus 16,

77
04:46.310 --> 04:49.010
- minus 24, and - minus 32.

78
04:49.640 --> 04:51.110
Just an exercise.

79
04:51.350 --> 04:54.770
We want to learn, practice how to access local variables.

80
04:54.770 --> 04:57.110
So okay, so let's do that now.

81
04:58.040 --> 05:01.550
So we assign the first one, we move

82
05:04.750 --> 05:08.320
the first local variable is - minus eight.

83
05:09.640 --> 05:11.680
- minus eight.

84
05:13.360 --> 05:15.580
And you move your - to

85
05:17.120 --> 05:17.900
yeah, whatever is there.

86
05:17.900 --> 05:19.010
That's your first argument.

87
05:21.810 --> 05:24.480
The second one would be

88
05:26.340 --> 05:27.030
-

89
05:30.230 --> 05:33.110
minus 16.

90
05:33.230 --> 05:37.580
This is the second local variable, and you're going to save your second argument there.

91
05:37.790 --> 05:38.450
-.

92
05:39.850 --> 05:42.160
Your third local variable

93
05:44.290 --> 05:54.010
is - minus 24, and you are going to save your third argument there.

94
05:55.270 --> 06:03.400
Your fourth local variable is - minus 32.

95
06:03.400 --> 06:07.330
And you are going to save your fourth argument there.

96
06:08.440 --> 06:08.980
That's it.

97
06:09.700 --> 06:11.560
Now remember, this is not optimized code yet.

98
06:11.560 --> 06:12.010
I'm not,

99
06:12.010 --> 06:14.410
we are not aiming for optimizing the code.

100
06:14.410 --> 06:22.570
We are aiming to learn how to use, uh, the offsets for the variables and for the arguments.

101
06:22.960 --> 06:27.910
So that's why it seems long, although it's not necessary to do this.

102
06:27.910 --> 06:31.690
So this is how you access local variables using the offsets here,

103
06:31.720 --> 06:34.000
offsets here, minus.

104
06:34.660 --> 06:34.990
Right.

105
06:34.990 --> 06:40.360
So now we are going to do the addition. To do the addition,

106
06:40.540 --> 06:43.420
we are going to zero out the - first.

107
06:44.110 --> 06:45.670
So - -.

108
06:46.630 --> 06:54.730
Now we add the first, the first number, the first argument to the, uh, -.

109
06:55.480 --> 06:57.190
So we will take -.

110
06:57.850 --> 06:59.740
We are adding - to -.

111
06:59.890 --> 07:02.920
We are going to use the local variable to do that,

112
07:02.920 --> 07:06.490
since our first four arguments are already stored in the local variable.

113
07:06.490 --> 07:08.170
So let's learn how to do that,

114
07:08.170 --> 07:10.810
although this is not optimized code, remind you.

115
07:11.200 --> 07:14.410
So we are learning how to use those local variables.

116
07:15.250 --> 07:17.290
So the first one is add

117
07:18.460 --> 07:21.220
-, and then we will grab this local variable.

118
07:24.150 --> 07:29.880
So this is - minus eight, which stores your first argument,

119
07:30.120 --> 07:30.930
-.

120
07:33.220 --> 07:36.610
So maybe I just copy and paste, it's easier. Copy.

121
07:37.970 --> 07:46.280
Now the second one, I just change this to - minus 16 for the second local variable.

122
07:48.250 --> 07:54.010
And the third local variable, I paste again, this is - minus 24.

123
07:56.720 --> 08:00.320
And the last one, - minus 32.

124
08:04.260 --> 08:09.450
So at this point in time, you already added the first four arguments to -.

125
08:09.450 --> 08:13.920
So now we are going to add the five, six and seven.

126
08:15.180 --> 08:17.010
So add

127
08:23.280 --> 08:24.210
-.

128
08:26.710 --> 08:27.340
Keyword.

129
08:30.690 --> 08:34.080
The fifth argument is - plus 48.

130
08:41.010 --> 08:43.050
So we just copy and paste.

131
08:45.110 --> 08:48.500
Next one is the sixth argument, which is - plus 56.

132
08:51.230 --> 08:56.000
And the last one is the seventh argument, which is - plus 64.

133
09:02.400 --> 09:02.760
I see.

134
09:03.660 --> 09:07.770
So by now we should have the result inside -.

135
09:09.150 --> 09:10.500
So now we can clean the stack.

136
09:10.500 --> 09:13.350
So we add 32 bytes of local variables.

137
09:13.350 --> 09:17.790
So now we clean it, add - 32.

138
09:21.130 --> 09:24.760
Then we will, uh, clean the stack.

139
09:27.160 --> 09:27.610
Pop it.

140
09:30.240 --> 09:31.230
And return.

141
09:34.410 --> 09:34.800
Okay.

142
09:35.700 --> 09:37.110
Put a breakpoint here.

143
09:37.110 --> 09:38.370
Run to the breakpoint.

144
09:38.370 --> 09:39.180
Step over.

145
09:39.360 --> 09:45.480
Assign the first four arguments to -, -, -, -.

146
09:46.530 --> 09:54.870
Next, we create space, shadow space plus space for the three arguments left, which is five,

147
09:54.870 --> 09:57.060
six, and seven arguments on the stack.

148
09:57.600 --> 10:05.400
Then we assign, we assign this five to the fifth argument on the stack.

149
10:07.000 --> 10:09.520
Let me click on this.

150
10:09.520 --> 10:12.310
And you see now it's on the stack, five is there on the stack.

151
10:13.890 --> 10:16.440
Next we assign six.

152
10:16.440 --> 10:18.570
Click on this, six already on the stack.

153
10:20.370 --> 10:23.460
And the last one will be, uh, number seven.

154
10:24.570 --> 10:25.770
Right, click on that.

155
10:25.830 --> 10:27.930
You will see seven is also on the stack.

156
10:28.170 --> 10:28.560
Five,

157
10:28.560 --> 10:29.280
six, seven.

158
10:29.280 --> 10:30.240
All three are there.

159
10:30.420 --> 10:37.950
So at this point in time, you have first, second, third, fourth argument in the register, and then

160
10:37.950 --> 10:40.590
the fifth, sixth and seventh argument on the stack.

161
10:41.310 --> 10:43.080
Now we're going to call our function.

162
10:43.710 --> 10:45.030
We step into the function.

163
10:45.930 --> 10:46.710
We go there.

164
10:46.740 --> 10:49.290
Now we create our local frame pointer,

165
10:49.440 --> 10:50.670
our local stack frame.

166
10:51.030 --> 10:56.400
So by at this point in time, on this line here, our local stack frame is already created.

167
10:57.120 --> 11:01.350
So push - is your stack frame pointer for the function.

168
11:02.340 --> 11:05.520
65486588.

169
11:06.510 --> 11:10.500
From now on, we are going to create four local variables.

170
11:10.500 --> 11:20.340
So minus 32 bytes for four local variables. - 65 4DE8, which is here, 65

171
11:20.340 --> 11:21.360
4DE8 is here.

172
11:21.870 --> 11:24.690
Our - is FDE.

173
11:25.850 --> 11:26.630
Here.

174
11:28.780 --> 11:29.050
All right.

175
11:29.050 --> 11:33.490
So now we got four, 1, 2, 3, 4 local variables created.

176
11:33.730 --> 11:35.740
This is -, this is -.

177
11:38.030 --> 11:43.430
Now we assign our first argument to - minus eight.

178
11:44.180 --> 11:45.500
- minus eight.

179
11:47.880 --> 11:48.600
So let's do that.

180
11:49.080 --> 11:49.710
Step over.

181
11:50.800 --> 11:53.140
So you can see if we click on this one,

182
11:53.260 --> 11:54.430
we got one there.

183
11:56.490 --> 11:57.990
Okay, so the next one.

184
12:00.450 --> 12:02.370
Assign it to the stack.

185
12:02.400 --> 12:02.940
You got two.

186
12:06.350 --> 12:07.310
Next one.

187
12:08.030 --> 12:08.960
Click on this.

188
12:08.990 --> 12:13.220
Now we assign the third argument to the third local variable, which is here.

189
12:16.850 --> 12:17.120
Click,

190
12:17.240 --> 12:17.990
click back.

191
12:17.990 --> 12:25.010
Now the fourth argument is assigned to the fourth local variable, which is here, 1, 2, 3, 4.

192
12:25.370 --> 12:28.490
Now we XOR -, - becomes zero.

193
12:29.000 --> 12:30.350
Now we start adding them.

194
12:31.160 --> 12:36.920
So we access the first four local variables this way to add them to -.

195
12:39.130 --> 12:40.150
So you get one.

196
12:41.610 --> 12:42.120
Now we get three.

197
12:42.120 --> 12:42.570
Three,

198
12:42.570 --> 12:44.010
two plus one is three.

199
12:45.460 --> 12:47.050
Six, and finally ten.

200
12:47.410 --> 12:48.040
Then here

201
12:48.040 --> 12:49.090
should have 15.

202
12:49.870 --> 12:55.660
Uh, uh, five plus ten is 15, and then six plus 15 is 21.

203
12:55.660 --> 12:56.200
Correct?

204
12:57.010 --> 12:59.380
Seven plus 21 should be 28.

205
12:59.380 --> 13:00.670
So step over.

206
13:01.570 --> 13:02.470
Are we getting 28?

207
13:02.470 --> 13:03.490
What is 1C?

208
13:04.060 --> 13:07.540
So let's use our calculator here.

209
13:08.080 --> 13:14.050
So let's key in 1C and see what we get. 1C, 1C is 28, correct.

210
13:14.050 --> 13:17.110
So our result is correct, 28.

211
13:17.950 --> 13:28.600
So now we clean the stack, return, return up here, clean the stack in the main function.

212
13:29.590 --> 13:32.650
And now we move our result, which is 1C, into -.

213
13:35.680 --> 13:36.640
So that's it.

214
13:36.790 --> 13:43.240
This is how we can implement, uh, seven argument function call and also make use of local variables

215
13:43.240 --> 13:45.130
also inside the function.

216
13:45.130 --> 13:46.870
So that's all for this video.

217
13:46.870 --> 13:48.550
Thank you for watching.