The Call Stack

Sdílet
Vložit
  • čas přidán 15. 10. 2014
  • This computer science video illustrates how the call stack is used to manage the way procedures and functions call each other and pass parameters.

Komentáře • 122

  • @bigboypal
    @bigboypal Před 2 lety +82

    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!

  • @NoobUCantBeat
    @NoobUCantBeat Před 2 lety +9

    been studying this for a couple hours... this has been the most straight forward and simplest explanation that finally makes everything make sense! thanks!

  • @beverlyukandu9337
    @beverlyukandu9337 Před 4 lety +12

    This clarified 10 years of confusion with the ordering of how parameters are pushed onto the stack. Thanks!

  • @dickvanfreedman
    @dickvanfreedman Před 3 lety +7

    FINALLY this makes sense. You did a better job explaining than most professors and text books.

  • @Wrtvrxgvcf55
    @Wrtvrxgvcf55 Před 6 lety +1

    mate you keep surprising me by the amount of content your channel offers. high quality content as well.

  • @ostracean
    @ostracean Před 3 lety +1

    The first video to actually explain the difference between callee and caller cleanup of parameters

  • @keeganfisher1900
    @keeganfisher1900 Před 6 lety +1

    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!

  • @tobi3497
    @tobi3497 Před 7 lety +9

    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.

  • @humanflybzzz4568
    @humanflybzzz4568 Před 6 lety +2

    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!

  • @sidchakravarty
    @sidchakravarty Před 7 lety +16

    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?

  • @NOPerative
    @NOPerative Před 6 lety +14

    Sweet explanation.
    Call/stack frames can be extremely confusing for those whom are new to memory management at lower levels.

  • @mohalelebeya9469
    @mohalelebeya9469 Před 8 lety +3

    very clear and easy to follow, thanks guy!

  • @franhm100
    @franhm100 Před 5 lety +15

    I'm a new man now. Thanks!

  • @satyasingh6144
    @satyasingh6144 Před 3 lety +4

    So, no one noticed how insanely 'unique' the name of this channel is? I bet this channel started with the inception of CZcams.

  • @user-xo3fn1fj2g
    @user-xo3fn1fj2g Před 2 lety +1

    Wow thanks for the clear explanation, I’ve been banging my head trying to understand this. Watching this video made everything click in place

  • @SleepyLink1
    @SleepyLink1 Před 4 lety +3

    Great video! Thank you I was struggling with this concept a little, but it's very clear here.

  • @abdoullatifabdoumoussa1990

    Finally someone who makes this idea much clear for me. Thanks very much, thumb up

  • @kindalost1
    @kindalost1 Před 8 lety +1

    10x. elaborated and clear.

  • @pumbo_nv
    @pumbo_nv Před 9 lety +48

    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.

    • @frankmadrid6198
      @frankmadrid6198 Před 5 lety +2

      Video states this at 5:45

    • @medvfx3370
      @medvfx3370 Před 5 lety +3

      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
      @@frankmadrid6198

  • @evolvOwns
    @evolvOwns Před 6 lety

    Wow, excellent conceptual explanation.

  • @OneNordicWarrior
    @OneNordicWarrior Před 7 lety +1

    Kevin, you're my man!

  • @henrychen1595
    @henrychen1595 Před 3 lety +1

    Question: Are the parameters and variables shuffled out of the stack if the procedure traverses it but does not use it?

  • @Xpingwinz
    @Xpingwinz Před 9 lety

    Awesome video and thank you!!

  • @gristlelollygag
    @gristlelollygag Před 4 dny

    This is fantastic, thank you!

  • @davidnguyen9023
    @davidnguyen9023 Před 15 dny

    This is great, thank you!

  • @johnywhy4679
    @johnywhy4679 Před 4 lety +1

    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.

  • @magica2z
    @magica2z Před 5 lety +1

    Great video.. Thank you and Subscribed..

  • @cm5754
    @cm5754 Před 3 lety +1

    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.

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 3 lety +1

      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

  • @lizdenhup
    @lizdenhup Před 4 lety +2

    Such a helpful video! I love this channel!!

  • @arturasbrk5521
    @arturasbrk5521 Před 6 lety +1

    10 out of 10 ! very helpful!

  • @BB-wh2vm
    @BB-wh2vm Před 3 lety +1

    Truly amazing explanation, thank you.

  • @alimeree4299
    @alimeree4299 Před 8 lety

    thanks allot man , very clear ..
    keep going ..

  • @bettyswunghole3310
    @bettyswunghole3310 Před 3 lety

    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.

  • @TomerBenDavid
    @TomerBenDavid Před 4 lety +2

    By far the best explanation please continue uploading videos

  • @NinaHProductions1
    @NinaHProductions1 Před 7 lety

    Is this for all stacks i.e. does this work for the JVM?

  • @LongVu-sm8wm
    @LongVu-sm8wm Před 2 lety

    thanks. the explanation is very clear.

  • @anirudh8575
    @anirudh8575 Před 5 lety

    Is there any specific reason why the parameters are stored in the reverse order on the stack?

  • @rajeevsawant2281
    @rajeevsawant2281 Před 6 lety

    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 ??

  • @jjjww975
    @jjjww975 Před 6 lety +1

    Well done!

  • @SJ_46
    @SJ_46 Před 2 lety +1

    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?

  • @jedmuff5597
    @jedmuff5597 Před 6 lety

    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?

  • @zoutuzhuren3370
    @zoutuzhuren3370 Před 6 lety

    thank you, this is really really Great!!!

  • @arpittiwari3749
    @arpittiwari3749 Před 4 měsíci

    Very straightforward answer

  • @humanflybzzz4568
    @humanflybzzz4568 Před 4 lety +1

    Amazingly explained indeed ! Could you please do a vid on the topic of GOT and PLT tables, as well as got.plt ....

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 4 lety

      I am planning to do a video on linkers and loaders. In the mean time, you might find my playlist on compilers interesting: czcams.com/video/cxNlb2GTKIc/video.html

  • @YuhuiZHI
    @YuhuiZHI Před 6 lety

    Very nice video. No technical word but very clear.

  • @tobiasdummling6144
    @tobiasdummling6144 Před 4 lety

    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)?

  • @laurentiustefan398
    @laurentiustefan398 Před 4 lety +2

    great vid.

  • @Nobody-df7vn
    @Nobody-df7vn Před 3 lety +3

    Hi, do you have a video on binding? and how different binding works? AMAZING VIDEO BTW!

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 3 lety +1

      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:
      czcams.com/video/aoZeeKXL4aM/video.html
      czcams.com/video/9Uy4k9znenE/video.html

  • @muktadir.rahman
    @muktadir.rahman Před 8 lety

    Thank you so much for this video.

  • @mariyehcloud
    @mariyehcloud Před rokem +1

    well explained! thanks a lot

  • @rajvijay3276
    @rajvijay3276 Před 6 lety +1

    perfect

  • @tharangamadhusankha
    @tharangamadhusankha Před 6 měsíci

    Thank you

  • @sinisatadic1959
    @sinisatadic1959 Před 8 lety +1

    Excellent! :)

  • @violinsheetmusicblog
    @violinsheetmusicblog Před 6 lety

    thank you!!!!!

  • @bestsaurabh
    @bestsaurabh Před 2 lety +1

    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). ??

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 2 lety +1

      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

  • @Decco6306
    @Decco6306 Před 4 lety +2

    thank you for these

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 4 lety +1

      My pleasure. :)KD

    • @Decco6306
      @Decco6306 Před 4 lety +1

      @@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)

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 4 lety +1

      Crikey! The Sinclair Z80 was my first ever computer, before I upgraded to a Spectrum. You might enjoy Ben Eater's channel. czcams.com/channels/S0N5baNlQWJCUrhCEo8WlA.html

    • @Decco6306
      @Decco6306 Před 4 lety +1

      @@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.

  • @ppotter10
    @ppotter10 Před 3 lety

    Hardly any video that explains how the stack is actually being used. Thanks!

  • @coasterfreak-486
    @coasterfreak-486 Před 2 lety +1

    Informative video

  • @poojanaregal9907
    @poojanaregal9907 Před 6 lety

    Can u get us a opengl program for this ...

  • @user-fh2mz9gz8k
    @user-fh2mz9gz8k Před 7 měsíci +1

    i love u, you are a hero

  • @MRAXELGRINDER
    @MRAXELGRINDER Před 4 lety +1

    great

  • @akashkhunt4191
    @akashkhunt4191 Před 4 lety

    Hi, Why does all recursion calls have same return address ?
    Thank you

    • @jdeleca
      @jdeleca Před 4 lety

      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

  • @guilhermetomishiyoteixeira4731

    Thank you! Not that hard...I was looking around the internet trying to get a better grasp in the subject.

  • @gaithsabah1026
    @gaithsabah1026 Před 4 lety +1

    Thanks

  • @EnesSarac-gh9dl
    @EnesSarac-gh9dl Před měsícem +1

    i like the channel.

  • @thlu308
    @thlu308 Před 6 lety

    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.

    • @yaroxkendo3043
      @yaroxkendo3043 Před 5 lety

      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.

  • @YouB3anz
    @YouB3anz Před 4 lety +1

    nice bass

  • @mushahidhussain1516
    @mushahidhussain1516 Před 5 lety +3

    Your voice man.

  • @rkorandyortan1
    @rkorandyortan1 Před 5 lety +1

    Saintgits peopls....Like adikke...😋🙋‍♂️

  • @RahulKumar-ci4by
    @RahulKumar-ci4by Před 3 lety +1

    Good very good

  • @cslogs1633
    @cslogs1633 Před 4 lety +1

    cool

  • @stevedcohen
    @stevedcohen Před 4 lety +1

    Great video, although it would have been better to use 83 procedures instead of 4.

  • @saurabhjha8733
    @saurabhjha8733 Před 7 měsíci

    what if procedure 4 calls procedure 5?

  • @isouravgope
    @isouravgope Před 26 dny

    bro is defining a recursion

  • @sia3540
    @sia3540 Před 2 lety

    How do I troubleshoot Windows 10 error "new guard page for the stack cannot be created"? I know nothing about programing!

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 2 lety +1

      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

    • @sia3540
      @sia3540 Před 2 lety

      @@ComputerScienceLessons Thanks for replying! I will try your suggestions.

  • @allisonscanlan4144
    @allisonscanlan4144 Před 2 lety

    Great video but the sound static makes it hard to listen

  • @SwissPhil02
    @SwissPhil02 Před 2 lety +1

    I thought the stack grew downwards not upwards ???

    • @ComputerScienceLessons
      @ComputerScienceLessons  Před 2 lety +2

      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

  • @johnywhy4679
    @johnywhy4679 Před 4 lety

    Awesome vid! But, could have been made shorter by eliminating one or two procedures. After P2, it's just redundant.

  • @shalineebhawnani
    @shalineebhawnani Před 7 lety

    itti English aati to video dekhne ko jarurt ni padhti

  • @J2897Tutorials
    @J2897Tutorials Před 8 lety +3

    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...