Why do computer scientists have to overcomplicate the stack so much? You are the first person that I've found to give a straightforward explanation of the order in which the stack frame is created. Thank you very much!
been studying this for a couple hours... this has been the most straight forward and simplest explanation that finally makes everything make sense! thanks!
A truly great explanation; I'd watched a previous one filled with ambiguity, and lacking the actual detail you coherently portrayed - I'll be sure to explore your series.
this helped me get over some confusion with implementing recursion in assembly... I was forgetting that the arguments should be considered part of the called procedures stack frame!!! thank you!
Thank you Kevin for creating this video. This is one of the best videos I saw that clearly explained call stack. Do you have any videos on Heap Memory?
It should be noted that parameters are not always passed through the stack. It depends on calling convention and architecture. For example, on x64 first several parameters are passed in registers.
Fantastic and eloquent explanation!!! This is a bit of a tough nut to crack on a first few tries, kinda like learning subnetting for the first time. I like how you don't just attack the viewer with a barrage of concepts rushing to complete the video, so that the ones with add can follow more easily :) Thanks dude!
It is interesting to present things in terms of popping individual elements off the stack, rather than just accessing them directly in memory and then restoring the frame pointer one time when a procedure returns.
I agree; this is an abstract view of an abstract data structure. My videos on the stack data structure mention how a stack might actually be implemented. :)KD
4:50 : Unclear: In the scheme described, parameters passed from P1 to P2 are pushed onto stack before P1 address. Thus, P2 must clean up the parameters P1 passed to it. This was confusingly stated in the vid as "P1 must clean up the stack". Confusing since it was implied (but not stated) that, in the alternate scheme, P1 must clean up the parameters it passes to P2.
I am planning to do a video on linkers and loaders. In the mean time, you might find my playlist on compilers interesting: ua-cam.com/video/cxNlb2GTKIc/v-deo.html
Thanks for the comment. :)KD I haven't covered binding explicitly, but it does come up in some of my videos. I have made a series of Python programming videos which mentions implicit variable declaration; in Python, a variable need not be declared explicitly, as it must in VB.NET (with Dim or Public), rather, Python infers the variable data type from the data you assign. This is called dynamic binding. I have also made a series of videos on object oriented programming with VB.NET. This includes a technique known as method overloading. When a program that calls an overloaded method is compiled, the compiler has to work out which variation of the method will be called at runtime based on its method signature. This 'resolved' call becomes part of the compiled code. This is known as static binding. These videos might help: ua-cam.com/video/aoZeeKXL4aM/v-deo.html ua-cam.com/video/9Uy4k9znenE/v-deo.html
Do you have to manually push the return address onto the stack and then manually pop it back to the program counter? Forgive me if this is a dumb question...I'm a bit of a noob, and so far I've only seen the "ret" instruction that seems to "magically" take care of return addresses.
Great explaination, one equestion: Why doesn't the initial frame or main() frame have any return address? I know that it's the first func, still the control goes to somewhere, r8? Maybe to the OS or somewhere.. Can you pls put some light on it?
Great explaination. One question: Why are agruments of a function read from right to left? The right most argument is at the bottom of the stack. Can someone please help me understand what if we read it other way round( left to right). ??
Interesting question. I believe it has to do with the fact that functions can be defined with optional parameters. For example, here is a VB.NET function definition with two mandatory parameters, a and b, and an optional parameter. Function myFunction(a As Integer, b As Integer, Optional c As Integer = 0) Any optional parameters must be specified at the right hand side of the comma separated list. When these arguments are read onto the stack, the mandatory ones will end up at the top, and their memory locations (offsets) will be known at compile time, so it's possible to access them more easily. Optional arguments, which may or may not be there, are lower down. :)KD
What I dont understand is how can the subprocess read their parameters? They pop the return address and than it says the next process cleans up the stack. But shouldnt it be cleaned up by the process automatically as it has to pop the parameters to read them (LIFO)?
@@ComputerScienceLessons Im working on a smol z80 computer with 32k ram and rom and an 8255 pia for io this has helped my digest the information in the datasheets they throw out at you with no context as well as under the assumption you know what they are talking about. I got it to blink an led and im so happy. thanks again! (apparently they still make the 8 bit z80 and other supporting chips from zilog brand new. you can buy from Mouser.com and digikey.com as well as the 6502 from WDC from the same two suppliers mentioned)
Crikey! The Sinclair Z80 was my first ever computer, before I upgraded to a Spectrum. You might enjoy Ben Eater's channel. ua-cam.com/channels/S0N5baNlQWJCUrhCEo8WlA.html
@@ComputerScienceLessons that's neat. My first PC was a win 98 PC from Packard Bell. play command & conquer for hours on end. mind you, this was wayyyy out of date. I got this in 2005.And you're too late! I'm already caught up with his videos! you're videos are filler for more "modern/relevant" topics if you will.
So what is the "Stack"? An order that the procedures must follow when carrying out there instructions? Like a BODMAS sort of thing that they do in maths? Or is it more like how the computer sorts out the procedures that are calling each one another? Also, which way does the procedure have to travers the stack(top to bottom or bottom to top) and does the procedure do the whole stack or does the procedure just do its selected stack frame?
Wouldn't it make more sense to push the return address first, then the parameters? This way, when the called function returns control to the calling function, the stack frame is already clean.
It's really just a conventional issue to decide who is responsible to clear the stack. In the given design, the procedure which pushed the parameters is responsible to pop them again. When programming in Assembler you can 'abuse' this functionality whenever you push the same parameters over and over again to (different) procedures, so you don't even need to push pop them over and over again, just once pushing them onto the stack when calling the first procedure and popping them after a last call.
Hi , Can you please give an example (name of the architecture )where the above implementation method of pushing the parameters first and then pushing return addr of previous procedure is implemented ??
This error indicates that you are low on memory, or virtual memory. (Virtual memory is a swap file on your hard drive, or SSD, that is used to supplement the RAM when it's getting full.) The circumstances under which the error appears are important. Is it being triggered when you are playing a particular game? Does your computer meet the requirements of the software you are using? What has changed since you started seeing the error message - did it start after you download something? Grand Theft Auto for example can be problematic. A lot of computers these days boot from an SSD (solid state drive). The SSD holds the operating system (such as Windows) and is usually labelled drive C. SSDs tend to have a much lower capacity than magnetic drives and will fill up quickly if you install all of your applications on it, leaving little space for virtual memory. How full is your drive C looking? (Click on This PC in File Explorer to check.) If your computer has another (magnetic) drive (labelled drive D), install your software there instead of the SSD in future. You could also try moving some of your software from C to D. (I put all of my Epic and Steam games on drive D). Be careful how you do this, you can't just cut and paste files. Maybe you could also do with a general clear out. Uninstall any applications (incl. games) that you don't use anymore, and delete any photos and videos you don't want to keep (or move them to an external drive). Be careful not to throw the baby away with the bath water! You could also defragment your drive if you haven't done it for a while (right click the drive in File Explorer and select Properties then Tools). If you have a PC that you can expand, you could also consider putting some more RAM sticks inside it (but make sure you research how to do this, or get someone else to do it for you, if you are not sure what to do). Good luck :)KD
At the risk of sounding glib, it's a matter of perspective. These are abstract diagrams. Conventionally, you are correct, but my students find it more intuitive to imagine it growing up. :)KD
I can't see no code, circuit, tracks, ICs, nor electrons, just silly diagrams. Still makes no sense. So a clicking I will go, a clicking I will go, E I antio, a clicking I will go...
Why do computer scientists have to overcomplicate the stack so much? You are the first person that I've found to give a straightforward explanation of the order in which the stack frame is created. Thank you very much!
My motto - K.I.S.S. :)KD
Some of them don't really understand it themselves.
This clarified 10 years of confusion with the ordering of how parameters are pushed onto the stack. Thanks!
You're very welcome. :) KD
FINALLY this makes sense. You did a better job explaining than most professors and text books.
Thank you :)KD
been studying this for a couple hours... this has been the most straight forward and simplest explanation that finally makes everything make sense! thanks!
The first video to actually explain the difference between callee and caller cleanup of parameters
A truly great explanation; I'd watched a previous one filled with ambiguity, and lacking the actual detail you coherently portrayed - I'll be sure to explore your series.
Your comment is much appreciated.
Wow thanks for the clear explanation, I’ve been banging my head trying to understand this. Watching this video made everything click in place
You're welcome :)KD
Finally someone who makes this idea much clear for me. Thanks very much, thumb up
Thank you. Much appreciated :)KD
understanding this is so key to understanding recursion. Always having this knowledge in the back of your mind makes it easier
I agree. Understanding the recursive sorting algorithms depends on this :)KD
mate you keep surprising me by the amount of content your channel offers. high quality content as well.
So, no one noticed how insanely 'unique' the name of this channel is? I bet this channel started with the inception of UA-cam.
It was called Kevin Drumm to begin with - not so catchy :)KD
Sweet explanation.
Call/stack frames can be extremely confusing for those whom are new to memory management at lower levels.
I'm a new man now. Thanks!
this helped me get over some confusion with implementing recursion in assembly... I was forgetting that the arguments should be considered part of the called procedures stack frame!!! thank you!
By far the best explanation please continue uploading videos
Thanks. I really appreciate the comments.
Thank you Kevin for creating this video.
This is one of the best videos I saw that clearly explained call stack.
Do you have any videos on Heap Memory?
It should be noted that parameters are not always passed through the stack. It depends on calling convention and architecture. For example, on x64 first several parameters are passed in registers.
that's not what he said, he was talking about the return value, which is what happens in cdecl the return adress is in EAX
@Frank Madrid
Fantastic and eloquent explanation!!! This is a bit of a tough nut to crack on a first few tries, kinda like learning subnetting for the first time. I like how you don't just attack the viewer with a barrage of concepts rushing to complete the video, so that the ones with add can follow more easily :) Thanks dude!
Great video! Thank you I was struggling with this concept a little, but it's very clear here.
You're welcome :)KD
It is interesting to present things in terms of popping individual elements off the stack, rather than just accessing them directly in memory and then restoring the frame pointer one time when a procedure returns.
I agree; this is an abstract view of an abstract data structure. My videos on the stack data structure mention how a stack might actually be implemented. :)KD
Such a helpful video! I love this channel!!
Thanks for the comment. :) KD
4:50 : Unclear: In the scheme described, parameters passed from P1 to P2 are pushed onto stack before P1 address. Thus, P2 must clean up the parameters P1 passed to it. This was confusingly stated in the vid as "P1 must clean up the stack". Confusing since it was implied (but not stated) that, in the alternate scheme, P1 must clean up the parameters it passes to P2.
Truly amazing explanation, thank you.
Thank you :)KD
Informative video
Thank you :)KD
very clear and easy to follow, thanks guy!
Question: Are the parameters and variables shuffled out of the stack if the procedure traverses it but does not use it?
Very nice video. No technical word but very clear.
"Everything should be made as simple as possible, but not simpler" :)
Amazingly explained indeed ! Could you please do a vid on the topic of GOT and PLT tables, as well as got.plt ....
I am planning to do a video on linkers and loaders. In the mean time, you might find my playlist on compilers interesting: ua-cam.com/video/cxNlb2GTKIc/v-deo.html
Wow, excellent conceptual explanation.
thanks. the explanation is very clear.
This is fantastic, thank you!
Hi, do you have a video on binding? and how different binding works? AMAZING VIDEO BTW!
Thanks for the comment. :)KD
I haven't covered binding explicitly, but it does come up in some of my videos. I have made a series of Python programming videos which mentions implicit variable declaration; in Python, a variable need not be declared explicitly, as it must in VB.NET (with Dim or Public), rather, Python infers the variable data type from the data you assign. This is called dynamic binding. I have also made a series of videos on object oriented programming with VB.NET. This includes a technique known as method overloading. When a program that calls an overloaded method is compiled, the compiler has to work out which variation of the method will be called at runtime based on its method signature. This 'resolved' call becomes part of the compiled code. This is known as static binding.
These videos might help:
ua-cam.com/video/aoZeeKXL4aM/v-deo.html
ua-cam.com/video/9Uy4k9znenE/v-deo.html
Very straightforward answer
Do you have to manually push the return address onto the stack and then manually pop it back to the program counter?
Forgive me if this is a dumb question...I'm a bit of a noob, and so far I've only seen the "ret" instruction that seems to "magically" take care of return addresses.
Great explaination, one equestion: Why doesn't the initial frame or main() frame have any return address? I know that it's the first func, still the control goes to somewhere, r8? Maybe to the OS or somewhere.. Can you pls put some light on it?
Hardly any video that explains how the stack is actually being used. Thanks!
This is great, thank you!
well explained! thanks a lot
Thank you :)KD
Great explaination. One question: Why are agruments of a function read from right to left? The right most argument is at the bottom of the stack.
Can someone please help me understand what if we read it other way round( left to right). ??
Interesting question. I believe it has to do with the fact that functions can be defined with optional parameters. For example, here is a VB.NET function definition with two mandatory parameters, a and b, and an optional parameter.
Function myFunction(a As Integer, b As Integer, Optional c As Integer = 0)
Any optional parameters must be specified at the right hand side of the comma separated list.
When these arguments are read onto the stack, the mandatory ones will end up at the top, and their memory locations (offsets) will be known at compile time, so it's possible to access them more easily. Optional arguments, which may or may not be there, are lower down. :)KD
Kevin, you're my man!
What I dont understand is how can the subprocess read their parameters? They pop the return address and than it says the next process cleans up the stack. But shouldnt it be cleaned up by the process automatically as it has to pop the parameters to read them (LIFO)?
thank you for these
My pleasure. :)KD
@@ComputerScienceLessons Im working on a smol z80 computer with 32k ram and rom and an 8255 pia for io
this has helped my digest the information in the datasheets they throw out at you with no context as well as under the assumption you know what they are talking about.
I got it to blink an led and im so happy. thanks again!
(apparently they still make the 8 bit z80 and other supporting chips from zilog brand new. you can buy from Mouser.com and digikey.com as well as the 6502 from WDC from the same two suppliers mentioned)
Crikey! The Sinclair Z80 was my first ever computer, before I upgraded to a Spectrum. You might enjoy Ben Eater's channel. ua-cam.com/channels/S0N5baNlQWJCUrhCEo8WlA.html
@@ComputerScienceLessons that's neat. My first PC was a win 98 PC from Packard Bell. play command & conquer for hours on end. mind you, this was wayyyy out of date. I got this in 2005.And you're too late!
I'm already caught up with his videos! you're videos are filler for more "modern/relevant" topics if you will.
So what is the "Stack"? An order that the procedures must follow when carrying out there instructions? Like a BODMAS sort of thing that they do in maths? Or is it more like how the computer sorts out the procedures that are calling each one another? Also, which way does the procedure have to travers the stack(top to bottom or bottom to top) and does the procedure do the whole stack or does the procedure just do its selected stack frame?
Take a look at this one
ua-cam.com/video/niBsGw4h5yI/v-deo.html
Great video.. Thank you and Subscribed..
Is there any specific reason why the parameters are stored in the reverse order on the stack?
10 out of 10 ! very helpful!
Is this for all stacks i.e. does this work for the JVM?
10x. elaborated and clear.
thanks allot man , very clear ..
keep going ..
great vid.
Wouldn't it make more sense to push the return address first, then the parameters? This way, when the called function returns control to the calling function, the stack frame is already clean.
It's really just a conventional issue to decide who is responsible to clear the stack. In the given design, the procedure which pushed the parameters is responsible to pop them again. When programming in Assembler you can 'abuse' this functionality whenever you push the same parameters over and over again to (different) procedures, so you don't even need to push pop them over and over again, just once pushing them onto the stack when calling the first procedure and popping them after a last call.
Awesome video and thank you!!
Well done!
Hi, Why does all recursion calls have same return address ?
Thank you
I think it's because it's calling it-self, well, it does need to call it self, just update the memory/registers inside a conditional loop
i love u, you are a hero
You are too kind :)KD
Great video, although it would have been better to use 83 procedures instead of 4.
I totally agree :)KD
Hi ,
Can you please give an example (name of the architecture )where the above implementation method of pushing the parameters first and then pushing return addr of previous procedure is implemented ??
How do I troubleshoot Windows 10 error "new guard page for the stack cannot be created"? I know nothing about programing!
This error indicates that you are low on memory, or virtual memory. (Virtual memory is a swap file on your hard drive, or SSD, that is used to supplement the RAM when it's getting full.) The circumstances under which the error appears are important. Is it being triggered when you are playing a particular game? Does your computer meet the requirements of the software you are using? What has changed since you started seeing the error message - did it start after you download something? Grand Theft Auto for example can be problematic. A lot of computers these days boot from an SSD (solid state drive). The SSD holds the operating system (such as Windows) and is usually labelled drive C. SSDs tend to have a much lower capacity than magnetic drives and will fill up quickly if you install all of your applications on it, leaving little space for virtual memory. How full is your drive C looking? (Click on This PC in File Explorer to check.) If your computer has another (magnetic) drive (labelled drive D), install your software there instead of the SSD in future. You could also try moving some of your software from C to D. (I put all of my Epic and Steam games on drive D). Be careful how you do this, you can't just cut and paste files. Maybe you could also do with a general clear out. Uninstall any applications (incl. games) that you don't use anymore, and delete any photos and videos you don't want to keep (or move them to an external drive). Be careful not to throw the baby away with the bath water! You could also defragment your drive if you haven't done it for a while (right click the drive in File Explorer and select Properties then Tools). If you have a PC that you can expand, you could also consider putting some more RAM sticks inside it (but make sure you research how to do this, or get someone else to do it for you, if you are not sure what to do). Good luck :)KD
@@ComputerScienceLessons Thanks for replying! I will try your suggestions.
I thought the stack grew downwards not upwards ???
At the risk of sounding glib, it's a matter of perspective. These are abstract diagrams. Conventionally, you are correct, but my students find it more intuitive to imagine it growing up. :)KD
thank you, this is really really Great!!!
Cheers :)
Great video but the sound static makes it hard to listen
Excellent! :)
Tnx
bro is defining a recursion
nice bass
what if procedure 4 calls procedure 5?
Your voice man.
Thank you! Not that hard...I was looking around the internet trying to get a better grasp in the subject.
Good very good
Thank you :)KD
Can u get us a opengl program for this ...
Thank you
Thank you so much for this video.
perfect
Thanks
You're welcome :)KD
great
Saintgits peopls....Like adikke...😋🙋♂️
cool
:)KD
thank you!!!!!
Awesome vid! But, could have been made shorter by eliminating one or two procedures. After P2, it's just redundant.
itti English aati to video dekhne ko jarurt ni padhti
I can't see no code, circuit, tracks, ICs, nor electrons, just silly diagrams. Still makes no sense. So a clicking I will go, a clicking I will go, E I antio, a clicking I will go...