Hello, this is Dr. Miller, and this
is Episode six point five of
Assembly.
Today, we're going to talk about a
function prolog and then example
code, so the function
Prolog, so the function
Prolog is what we do when we enter a
function. It's a setup to
create the function so that people
can program in it.
And most compilers will do this
automatically.
And we've already seen examples of
it.
And so one of the things that it
does, it saves the EBP register
because it's going to use that as
our base pointer.
So the EBP register
or extended base pointer gives
you a constant point of reference.
And so when we in the future get to
talking about arguments
and parameters, the EBP register
gives us a constant way to reference
those.
So this is the code that is the
Prolog.
So first we are going to save onto
the stack the old version of SBP.
So push EBP now that's on top
of the stack.
And then we set the base pointer to
the E.S.P pointer or
extended stack pointer.
So we say move EBP VSP.
Now SBP is pointing to its
old version of itself and
then we have arguments that are at
different levels from there.
So here's an example.
So we have the top of our stack.
We've got a couple of pushes here.
We've got a call of a function.
We fix the stack when
we're done and then the inside
of our function, we have our
function. Prologs so pushy VPE
movie PSP.
So here we can just view the stack
as we go through.
So when we execute this push
beef beef, right, that's on top of
the stack now we're going to push
Cafer onto the Stack Cafe Cafe.
Now we're going to call the
function. And remember, when we call
the function, the return address is
going to get pushed on top of the
stack and then we'll enter that
function as the next instruction
will execute.
So on top of our stack is our return
address, and then we have down here
Cafe Cafe and then beef beef fried,
so they keep getting pushed down.
So now we're going to save VPE.
So our old EVP is now stored
on the stack and now we set
EBP to E.S.P.
So now EBP points to this constant
location and so
from here, EBP plus four
is our return address, plus eight
is Cafe, a cafe and plus 12
is beef beef.
So, again, this is going to give us
a constant reference point.
So here is the full example.
So we have our enter
and push A and our pop and
then we're all done and
then we have our pushes here are
called to our function, we correct
the stack.
And then inside of our function, we
have the Prolog and next time we'll
talk about the epilog.
So today, we talked about the Prolog
and then I showed you the example
code that we have for that,
looking forward, we're going to talk
about aFunction Epilog.
And then our quiz, what is the
Prolog consist of?
It consists of the code Bush EBP
Move, SBP E.S.P.
If you have questions, you can email
me at Miller, M.J., you and
Edu, and you can find me on Twitter
at Milhouse 30.