Ever wonder how your program remembers where to return after calling a function? That's the call stack's job.<br /><br />In this clear, whiteboard-style explanation we cover:<br />- What the call stack actually is<br />- How call frames are built and what they contain<br />- Return addresses, function arguments, local variables<br />- Why recursion works (until you overflow the stack)<br />- Stack vs heap memory differences<br />- Why too much recursion = crash<br /><br />Great for beginners to intermediate programmers who want to understand what's happening under the hood. References Ed Jorgensen's excellent (and free) x86-64 assembly book.<br /><br />00:00 Introduction to the Call Stack<br />00:16 Prerequisites - Understanding Basic Stacks<br />00:41 Simple Example Program with Function Calls<br />01:24 Function Call Chain and Recursion Example<br />02:20 Visualizing the Call Sequence<br />03:06 Local Variables and Return Values<br />03:55 Quick Recap - How Generic Stacks Work<br />04:34 Stacks Can Hold Any Data Type<br />05:36 Introducing the Call Frame Concept<br />06:22 What Belongs Inside a Call Frame<br />07:00 Return Address Explained<br />07:44 How the CALL Instruction Works<br />08:32 Function Arguments on the Stack<br />09:57 Extra Arguments Beyond Registers<br />10:19 Preserving Registers (Callee-Saved)<br />11:12 Local Variables on the Stack<br />11:40 Multiple Call Frames Example<br />12:54 Tracing Function Calls Step by Step<br />13:21 Starting with Main's Call Frame<br />15:00 Pushing Frames for Nested Calls<br />16:30 Returning - Popping Frames<br />18:10 Why the Stack is Perfect for Returns<br />19:45 Recursion and Multiple Instances<br />21:30 Stack Grows Downward in Memory<br />23:10 Stack vs Heap Memory Comparison<br />25:12 Local Variables vs Dynamically Allocated Memory<br />26:16 Pointers on Stack Pointing to Heap<br />27:32 Automatic Cleanup of Stack Variables<br />28:00 Memory Leaks with Heap Allocations<br />28:56 Recommended Reading - Ed Jorgensen Book<br />29:56 Call Frame Layout in x86-64 Assembly<br />31:16 Process Memory Layout Overview<br />32:22 Stack Grows Down, Heap Grows Up<br />33:52 Stack Overflow from Deep Recursion<br />35:09 Summary - Why the Call Stack Matters<br />35:28 Closing Remarks and Call to Subscribe<br /><br />=-=-=-=-=-=-=-=-=<br /><br />Thanks for watching!<br /><br />Find us on other social media here:<br />- https://www.NeuralLantern.com/social<br />- Twitter / X: https://x.com/NeuralLantern<br />- Rumble: https://rumble.com/c/c-3696939<br />- BitChute: https://www.bitchute.com/channel/pg1Pvv5dN4Gt<br />- Daily Motion: https://www.dailymotion.com/neurallantern<br />- Minds: https://www.minds.com/neurallantern/<br />- Odysee: https://odysee.com/@NeuralLantern:5<br /><br />Please show your support!<br /><br />- Buy me a coffee: https://ko-fi.com/neurallantern<br /><br />- Subscribe + Sharing on Social Media<br />- Leave a comment or suggestion<br />- Subscribe to the Blog: https://www.NeuralLantern.com<br />- Watch the main "pinned" video of this channel for offers and extras<br /><br /><br />
