Unpickling Stack Underflow | Assembly – Stack Overflow And Underflow

Jamie King

Subscribe Here





Assembly - Stack Overflow And Underflow


When we come to the data section here that we’ve seen in previous videos and I need to say, I need a temporary piece. It’s a useful piece piece of Ram. I will say memory and give it a data type. D word, which means 4 bytes and lets initialize it to 0 This is called static memory, meaning that memory will exist for the entire program. It doesn’t come anywhere in the middle of the program, nor does it leave anywhere. In the middle of the program. In fact, Statically, the assembler and the combine of the linker will create room for this piece of memory and the executable. And then when we load up the executable, this ran. Is there OK? That’s static memory? On the other hand, we have memory called dynamic memory and the stack is the first piece of dynamic memory we have seen. However, the stack is kind of a hybrid between static and dynamic, meaning the static part is the stack has a fixed size. In fact, you can see here with this directive. We say we need 100 hex bytes, which is 256 in decimal. We need that many bytes for the stack so in the program. When this piece, the program starts up are assembled code, we get 256 bytes and then we can push like we did in the last video and then push the 5 I believe we push the 1 I push the 2 and a 3 and a 4 and we were pushing those registers and each one is 4 bytes and we can push all day long, but then one if we kept pushing and exceeded our 256 byte limit, we would go off the top of the stack. Now what’s out here? It could be our static memory. It could be our code here, here’s. This is out here this this could be static memory. This could be code. It could be well. However, the Assembler and the Linker decided to put our code together in the executable image and and also with the operating system. How it Divis out? Ram, this could be anything and so if we go out and we start overriding this memory and say, it’s our code. All of a sudden were were changing our code at runtime. That’s bad, ok? That’s called a stack overflow. All right, going back to the the cafeteria example. If we had a lot of plates in fact, actually. I was at a local restaurant here one night and they have these containers, which they put all the glasses in. There’s these plastic crates and they fill these crates up with glasses so they can dry out. Oh, they can send them through the dishwasher, too and anyway. I was talking to the waiter. And he said they’re only supposed to stack them two. Maybe three high, but they had a new guy that night I was there, It was a late night and I me and a friend Were the only ones there, and this new guy stacked it and stacked it and stacked All This was such an epic experience. He took it all the way up here. Well, hopefully you can see a disaster about to happen here and sure enough. It did something happened and this stack overflowed, tipped over and it was a good thing. The restaurant was pretty much empty because these glasses went everywhere. It was a good. I’m not exaggerating was a good about 30 seconds of crash. Bang boom glass everywhere! It was awesome! It was well worth the price. I paid for my dinner that night to watch this experience, and the waiter told me that that was about 80% of the glasses that they owned and and that was a Friday night Saturday was the next day they had to scramble to get some new glasses anyway. That’s called stack overflow. We definitely do not want to do that in our own programs because no matter what’s out here. This memory out here, whether it’s code or maybe it’s our static data or maybe it’s dynamic memory, which? I’ll show you how to do in a much future video, but a future video down the road where we can create memory dynamically. Well, we just don’t want to go out there and start stomping on memory, and hopefully you’re seeing here like. I did in the last video. I forgot to put this return. Here, it’s an assembly programming. It’s up to us to be very diligent in particular about making sure our programs are correct. Because, yeah, you can go out in the memory and do what everyone read. Whatever he wants, we’re at the virus level here in a way, you can warp your code. All you want to you. Don’t have to return at the end of the procedure. It’s just a good idea anyway. I’m so boxing, but on that. No, we don’t want to push more than we have room for. We want to make sure we have enough room now. Don’t be dumb and say, give me tons of bytes because let’s add down this leaving a symbol. Let me try assembling this control shift. B, it’s like, hey, I’m too much. OK, we want to be wise. We want our stack to be big enough for our program, but no more, ok? I think all too often we get laziest programmers, and and I know in these examples. I haven’t been very diligent myself, but I’m just saying. Hey, I need 256 bytes of memory and generally, Yeah, that’s that’s probably way more than I’ll ever need for my stack. It depends on how many procedures I want to call will see as you call procedure that calls a procedure that calls a procedure that calls a procedure. Your stack will grow quite large, But if you’re super diligent about it, you’ll find out and you’ll do some analysis on your program and say how what’s the maximum stack? I’ll ever need if I call this thing as deep as it could possibly go, and then I’ll put that value here and not waste any memory, but chances are your times worth more than calculating that anyway. That’s that’s the whole trade-off. There is is how good are you, and is it really worth your time Religious debate? I’m sure we could have another problem. Is what if I go? Pop EAX and I just pop pop pop pop pop pop. Well, the stack start somewhere in memory. That’s here’s more. Ram, that’s not a Ram Ser. Stack is from here to here. Okay, that’s all of our start, stack memory, and maybe out here. The static data got put down here instead or our code got put down here or a dynamic memory doesn’t matter. This is not our memory, just the same as this is not our memory, but if we pop too much, we’ll end up, popping down below the stack, and that is called Stack Underflow, okay. We went too deep, which we don’t want to do as well inside of our procedures. We want to push on to the stack. That’s fine, we can push on to the stack. We don’t want to push too much. Though we don’t want to push beyond our upper boundary here and then and for every value, we pushed onto the stack. We want to be sure to pop it off. So in this case, if I’m pushing EAX, then then I only want one one one pop. Okay, for every push. We have a pop.

0.3.0 | Wor Build 0.3.0 Installation Guide

Transcript: [MUSIC] Okay, so in this video? I want to take a look at the new windows on Raspberry Pi build 0.3.0 and this is the latest version. It's just been released today and this version you have to build by yourself. You have to get your own whim, and then you...

read more