WEBVTT

00:01.710 --> 00:03.359
Hello, this is Dr. Miller, and this

00:03.360 --> 00:04.909
is Episode six point five of

00:04.930 --> 00:05.930
Assembly.

00:06.980 --> 00:08.359
Today, we're going to talk about a

00:08.360 --> 00:09.928
function prolog and then example

00:10.640 --> 00:12.589
code, so the function

00:12.590 --> 00:14.779
Prolog, so the function

00:14.780 --> 00:16.544
Prolog is what we do when we enter a

00:16.670 --> 00:18.710
function. It's a setup to

00:18.980 --> 00:21.019
create the function so that people

00:21.020 --> 00:22.020
can program in it.

00:22.160 --> 00:23.869
And most compilers will do this

00:23.870 --> 00:24.870
automatically.

00:25.040 --> 00:26.689
And we've already seen examples of

00:26.690 --> 00:27.690
it.

00:27.950 --> 00:28.999
And so one of the things that it

00:29.000 --> 00:30.829
does, it saves the EBP register

00:30.830 --> 00:32.289
because it's going to use that as

00:32.299 --> 00:33.299
our base pointer.

00:33.440 --> 00:35.329
So the EBP register

00:35.330 --> 00:37.369
or extended base pointer gives

00:37.370 --> 00:39.159
you a constant point of reference.

00:39.170 --> 00:40.879
And so when we in the future get to

00:40.880 --> 00:42.007
talking about arguments

00:43.220 --> 00:44.788
and parameters, the EBP register

00:45.350 --> 00:47.114
gives us a constant way to reference

00:47.270 --> 00:48.270
those.

00:49.550 --> 00:51.049
So this is the code that is the

00:51.050 --> 00:52.050
Prolog.

00:52.070 --> 00:53.749
So first we are going to save onto

00:53.750 --> 00:55.670
the stack the old version of SBP.

00:55.910 --> 00:57.331
So push EBP now that's on top

00:57.830 --> 00:58.830
of the stack.

00:59.090 --> 01:00.859
And then we set the base pointer to

01:00.860 --> 01:02.780
the E.S.P pointer or

01:02.990 --> 01:04.310
extended stack pointer.

01:04.640 --> 01:06.559
So we say move EBP VSP.

01:07.130 --> 01:09.229
Now SBP is pointing to its

01:09.230 --> 01:10.455
old version of itself and

01:11.060 --> 01:12.409
then we have arguments that are at

01:12.410 --> 01:14.029
different levels from there.

01:15.920 --> 01:17.030
So here's an example.

01:17.180 --> 01:18.650
So we have the top of our stack.

01:19.070 --> 01:20.629
We've got a couple of pushes here.

01:20.630 --> 01:22.149
We've got a call of a function.

01:22.400 --> 01:24.319
We fix the stack when

01:24.320 --> 01:26.389
we're done and then the inside

01:26.390 --> 01:28.879
of our function, we have our

01:29.150 --> 01:30.989
function. Prologs so pushy VPE

01:31.010 --> 01:32.209
movie PSP.

01:33.450 --> 01:35.219
So here we can just view the stack

01:35.220 --> 01:36.220
as we go through.

01:36.870 --> 01:38.700
So when we execute this push

01:38.910 --> 01:40.576
beef beef, right, that's on top of

01:40.770 --> 01:42.689
the stack now we're going to push

01:42.690 --> 01:44.909
Cafer onto the Stack Cafe Cafe.

01:45.990 --> 01:46.799
Now we're going to call the

01:46.800 --> 01:48.389
function. And remember, when we call

01:48.390 --> 01:49.919
the function, the return address is

01:49.920 --> 01:51.509
going to get pushed on top of the

01:51.510 --> 01:53.029
stack and then we'll enter that

01:53.220 --> 01:54.659
function as the next instruction

01:54.660 --> 01:55.660
will execute.

01:56.360 --> 01:58.369
So on top of our stack is our return

01:58.370 --> 02:00.019
address, and then we have down here

02:00.020 --> 02:01.735
Cafe Cafe and then beef beef fried,

02:02.000 --> 02:03.300
so they keep getting pushed down.

02:04.280 --> 02:05.840
So now we're going to save VPE.

02:06.290 --> 02:07.662
So our old EVP is now stored

02:08.240 --> 02:10.099
on the stack and now we set

02:10.100 --> 02:11.509
EBP to E.S.P.

02:12.700 --> 02:14.949
So now EBP points to this constant

02:14.950 --> 02:15.950
location and so

02:17.080 --> 02:18.256
from here, EBP plus four

02:19.180 --> 02:21.069
is our return address, plus eight

02:21.070 --> 02:23.319
is Cafe, a cafe and plus 12

02:23.320 --> 02:24.410
is beef beef.

02:25.360 --> 02:26.649
So, again, this is going to give us

02:26.650 --> 02:28.220
a constant reference point.

02:30.610 --> 02:32.460
So here is the full example.

02:34.570 --> 02:35.570
So we have our enter

02:36.430 --> 02:37.704
and push A and our pop and

02:38.380 --> 02:39.507
then we're all done and

02:40.300 --> 02:41.889
then we have our pushes here are

02:41.890 --> 02:43.479
called to our function, we correct

02:43.480 --> 02:44.480
the stack.

02:44.530 --> 02:45.819
And then inside of our function, we

02:45.820 --> 02:47.289
have the Prolog and next time we'll

02:47.290 --> 02:48.610
talk about the epilog.

02:52.170 --> 02:53.879
So today, we talked about the Prolog

02:53.880 --> 02:55.409
and then I showed you the example

02:55.410 --> 02:56.759
code that we have for that,

02:58.710 --> 02:59.969
looking forward, we're going to talk

02:59.970 --> 03:01.259
about aFunction Epilog.

03:02.890 --> 03:04.360
And then our quiz, what is the

03:04.630 --> 03:05.830
Prolog consist of?

03:07.890 --> 03:09.929
It consists of the code Bush EBP

03:09.960 --> 03:11.370
Move, SBP E.S.P.

03:13.440 --> 03:14.759
If you have questions, you can email

03:14.760 --> 03:16.320
me at Miller, M.J., you and

03:16.620 --> 03:18.509
Edu, and you can find me on Twitter

03:18.510 --> 03:19.590
at Milhouse 30.

