Hello and welcome back.
This time we are going to do a function call with seven arguments.
So again, try to pause this video and try on your own.
See if you can do it.
And this time try to create local variables and try to make use of them as well.
And good luck.
All right.
So this is how we are going to do it.
We are going to reload our template as usual,
our template. We are going to create the seven arguments.
So the first one we are going to move - one.
Second one is -, two. Third one is -, which is three. Fourth one is -, which is four.
And now we have to allocate space for
the variables, the arguments.
So the fifth, sixth and seventh, fifth, six and seven, five, six and seven arguments.
How many bytes?
24.
Why?
Because
three times eight.
We take three
times eight.
So that gives you 24 bytes, five, six and seven.
So 24 plus 32, 56 here, 56 bytes.
So total,
total is 32 plus 24.
That will give you 56.
So here we need to sub -.
56.
So 56 in hex is 38.
Now we can start to, uh, assign variables to the five, six and seven.
So to do that, we use the offset - plus 32, - plus 40, and - plus 48.
So fifth variable, move
- plus 32.
Move the fifth argument there.
- plus 40, sixth argument.
- plus 48
for the seventh argument.
Done.
Now we need a function call.
Maybe we choose somewhere down here.
Don't worry.
We can just overwrite all this.
We can actually
NOP
all this up.
Give us more space.
So let's select all this to NOP.
Binary fill NOPs.
Then we get more space to do our code.
All right.
So we got some space now to write our code.
So we choose something down here for our function, okay.
So our function call, let's say we choose a location somewhere down here.
Okay.
Copy that address.
You come here and make our call.
Call, paste the address.
When you come back, you must clean.
So you do an add -.
And here we need to clean 56 bytes.
Then
the result will be in -.
You can store it in - if you want.
So let's do that.
Move to - the result of the addition.
There you go.
Right.
So now it will call this function 401 5B4.
So here we implement a function, push -.
Move - -.
Then we create four local variables.
So we sub the - 32, 32 bytes here.
Now we try to move all our arguments to the local variable for exercise.
Let's move all our arguments, the first four arguments to our local variable, - minus eight, - minus 16,
- minus 24, and - minus 32.
Just an exercise.
We want to learn, practice how to access local variables.
So okay, so let's do that now.
So we assign the first one, we move
the first local variable is - minus eight.
- minus eight.
And you move your - to
yeah, whatever is there.
That's your first argument.
The second one would be
-
minus 16.
This is the second local variable, and you're going to save your second argument there.
-.
Your third local variable
is - minus 24, and you are going to save your third argument there.
Your fourth local variable is - minus 32.
And you are going to save your fourth argument there.
That's it.
Now remember, this is not optimized code yet.
I'm not,
we are not aiming for optimizing the code.
We are aiming to learn how to use, uh, the offsets for the variables and for the arguments.
So that's why it seems long, although it's not necessary to do this.
So this is how you access local variables using the offsets here,
offsets here, minus.
Right.
So now we are going to do the addition. To do the addition,
we are going to zero out the - first.
So - -.
Now we add the first, the first number, the first argument to the, uh, -.
So we will take -.
We are adding - to -.
We are going to use the local variable to do that,
since our first four arguments are already stored in the local variable.
So let's learn how to do that,
although this is not optimized code, remind you.
So we are learning how to use those local variables.
So the first one is add
-, and then we will grab this local variable.
So this is - minus eight, which stores your first argument,
-.
So maybe I just copy and paste, it's easier. Copy.
Now the second one, I just change this to - minus 16 for the second local variable.
And the third local variable, I paste again, this is - minus 24.
And the last one, - minus 32.
So at this point in time, you already added the first four arguments to -.
So now we are going to add the five, six and seven.
So add
-.
Keyword.
The fifth argument is - plus 48.
So we just copy and paste.
Next one is the sixth argument, which is - plus 56.
And the last one is the seventh argument, which is - plus 64.
I see.
So by now we should have the result inside -.
So now we can clean the stack.
So we add 32 bytes of local variables.
So now we clean it, add - 32.
Then we will, uh, clean the stack.
Pop it.
And return.
Okay.
Put a breakpoint here.
Run to the breakpoint.
Step over.
Assign the first four arguments to -, -, -, -.
Next, we create space, shadow space plus space for the three arguments left, which is five,
six, and seven arguments on the stack.
Then we assign, we assign this five to the fifth argument on the stack.
Let me click on this.
And you see now it's on the stack, five is there on the stack.
Next we assign six.
Click on this, six already on the stack.
And the last one will be, uh, number seven.
Right, click on that.
You will see seven is also on the stack.
Five,
six, seven.
All three are there.
So at this point in time, you have first, second, third, fourth argument in the register, and then
the fifth, sixth and seventh argument on the stack.
Now we're going to call our function.
We step into the function.
We go there.
Now we create our local frame pointer,
our local stack frame.
So by at this point in time, on this line here, our local stack frame is already created.
So push - is your stack frame pointer for the function.
65486588.
From now on, we are going to create four local variables.
So minus 32 bytes for four local variables. - 65 4DE8, which is here, 65
4DE8 is here.
Our - is FDE.
Here.
All right.
So now we got four, 1, 2, 3, 4 local variables created.
This is -, this is -.
Now we assign our first argument to - minus eight.
- minus eight.
So let's do that.
Step over.
So you can see if we click on this one,
we got one there.
Okay, so the next one.
Assign it to the stack.
You got two.
Next one.
Click on this.
Now we assign the third argument to the third local variable, which is here.
Click,
click back.
Now the fourth argument is assigned to the fourth local variable, which is here, 1, 2, 3, 4.
Now we XOR -, - becomes zero.
Now we start adding them.
So we access the first four local variables this way to add them to -.
So you get one.
Now we get three.
Three,
two plus one is three.
Six, and finally ten.
Then here
should have 15.
Uh, uh, five plus ten is 15, and then six plus 15 is 21.
Correct?
Seven plus 21 should be 28.
So step over.
Are we getting 28?
What is 1C?
So let's use our calculator here.
So let's key in 1C and see what we get. 1C, 1C is 28, correct.
So our result is correct, 28.
So now we clean the stack, return, return up here, clean the stack in the main function.
And now we move our result, which is 1C, into -.
So that's it.
This is how we can implement, uh, seven argument function call and also make use of local variables
also inside the function.
So that's all for this video.
Thank you for watching.