Hello. This is Dr Miller, and this is Episode 7.3 of Assembly.
Today we're gonna talk about enter and leave, and then useful Mac Rose,
So enter and leave are done during the prologue and epilogue.
And that is because doing the prologue and epilogue is a little bit tedious. You have to remember to instructions, do him in the right order.
And so the enter and leave instructions sort of fill that gap and make it a little bit easier for programmers.
So, for example, enter 00 enters ah, function and creates what we call a stack frame.
And so here we can see the definitions
where the first operandi is the amount of dynamic stories that you want.
And then the 2nd 1 talks about lexical nesting.
So typically, we only see either enter 00 or enter with the first argument is how maney, um, local variables you'd like to have
so might be four or eight, depending on how much space you want to allocate.
And so enter 00 does the following It does push e v p and then movie B p E S P,
whereas leave is what we used to exit a function. So what? This does the epilogue.
So leave does the following it will say movie spe, BP and then poppy BP.
Now what are the pros and cons? So the pro is that it's easier to write code. If you use, enter and leave,
you have to instructions instead of four.
Now the downside is that this is actually slower than doing it by hand if you know what you're doing and you know what instructions air faster than what other instructions.
So let's look at an example.
So previously we had done a example called Fu, and inside of it
we would use push and then popped. And this is an aversion using C.
And so what we can see is that in See it'll do. Instead of doing enter, it'll do pushy BP movie B P E S P.
But then, at the end, it does the leave instruction. And this is because using this instruction is faster than enter, and using this instruction is faster than doing it by hand.
And so what you'll see is you'll see a compiler will make a better optimization than what may be a programmer might do by hand.
And so this is one of the examples that we'll see where people who write compilers are writing for the code that'll go as fast as possible and use as little space is possible, and so they'll make those decisions.
So we do have some Mac Rose that we can use.
So Number one is we can talk about the stack size. So if you go to the Nazem documents, you can see the different types of stack size
so you can use small, flat large. So there are different sizes that we can use.
And then we've talked about Mac. Uh, we've talked about arguments to functions previously, and so instead of defining those buy an offset,
you can use basically a short cut. So every time I see exit will do, for example, E v P. Minus or plus eight, and every time I see why it might do plus 12 and Z plus 16
and so this will do all those calculations for you.
On the flip side, you can also use macros for local variables, although it's a little bit more complicated, so you can see here that it's gotta push some context and pop some context at the beginning in the end, and this is so that the assembler knows what you're doing.
And then here it's creating a variable inside of the assembler that we're never going to see. But this variable says, How many local variables do we have?
And then when we define each one of these local variables, little add So, for example, this will add four bites, and this allowed four bites.
So when it gets down to the end, it will actually just say enter eight comma zero if you disassemble it.
And so then you can just use this instead of having to keep track of which offset did I use for
X in Which one did I use for why or some or I? And in the future we're gonna look at an example showing that
so today we talked about enter and leave, and then we looked at some macros that you can use in order to make your life easier.
So looking forward will give an example of using enter and leave and arguments and converted from our previous example.
And then also we're gonna talk about floating point numbers
So here's our quiz. What is the equivalent of Enter zero comma? Zero as far as low level instructions,
and that's pushy. VP movie v P E S P.
What's the equivalent of leave?
That is movie spe BP Poppy VP.
If you have questions, you can contact me
the email at Miller MJ at you and Kate Ie to you, and you can find me on Twitter at Milhouse 30.