Assembly

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14

Video Transcription

00:01
Hello. This is Dr Miller, and this is Episode 7.3 of Assembly.
00:06
Today we're gonna talk about enter and leave, and then useful Mac Rose,
00:11
enter and leave.
00:13
So enter and leave are done during the prologue and epilogue.
00:17
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.
00:24
And so the enter and leave instructions sort of fill that gap and make it a little bit easier for programmers.
00:30
So, for example, enter 00 enters ah, function and creates what we call a stack frame.
00:37
And so here we can see the definitions
00:39
where the first operandi is the amount of dynamic stories that you want.
00:44
And then the 2nd 1 talks about lexical nesting.
00:48
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
00:57
so might be four or eight, depending on how much space you want to allocate.
01:00
And so enter 00 does the following It does push e v p and then movie B p E S P,
01:08
whereas leave is what we used to exit a function. So what? This does the epilogue.
01:14
So leave does the following it will say movie spe, BP and then poppy BP.
01:21
Now what are the pros and cons? So the pro is that it's easier to write code. If you use, enter and leave,
01:26
you have to instructions instead of four.
01:30
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.
01:41
So let's look at an example.
01:42
So previously we had done a example called Fu, and inside of it
01:48
we would use push and then popped. And this is an aversion using C.
01:53
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.
02:02
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.
02:15
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.
02:22
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.
02:35
So we do have some Mac Rose that we can use.
02:38
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
02:45
so you can use small, flat large. So there are different sizes that we can use.
02:53
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,
03:00
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
03:14
and so this will do all those calculations for you.
03:17
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.
03:34
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?
03:42
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.
03:50
So when it gets down to the end, it will actually just say enter eight comma zero if you disassemble it.
03:55
And so then you can just use this instead of having to keep track of which offset did I use for
04:02
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
04:14
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.
04:20
So looking forward will give an example of using enter and leave and arguments and converted from our previous example.
04:28
And then also we're gonna talk about floating point numbers
04:31
So here's our quiz. What is the equivalent of Enter zero comma? Zero as far as low level instructions,
04:40
and that's pushy. VP movie v P E S P.
04:44
What's the equivalent of leave?
04:47
That is movie spe BP Poppy VP.
04:53
If you have questions, you can contact me
04:56
the email at Miller MJ at you and Kate Ie to you, and you can find me on Twitter at Milhouse 30.

Up Next

Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

Instructed By

Instructor Profile Image
Matthew Miller
Assistant Professor at the University of Nebraska at Kearney
Instructor