x86-64 Assembly: Local Variables, Stack Frames & Alignment Explained

Quick but deep look at local variables on the stack in x86-64 assembly (YASM). We cover allocation with sub rsp, accessing via offsets, why the stack must be 16-byte aligned when calling libc functions like printf, and two practical ways to fix alignment crashes. Includes live segfault debugging and a full working example with a local array. Great for anyone studying systems programming, computer architecture, or just trying to figure out why their assembly program randomly crashes on a library call. Like + subscribe if you want more clear, practical assembly tutorials! 00:00 Introduction to Local Variables on the Stack 00:28 C++ Example of Function and Local Variables 01:06 Incoming Arguments in RDI vs Stack Variables 03:24 Pointers as Local Variables on Stack 04:34 Why the Stack ? Recursion and Multiple Calls 05:18 Visualizing Multiple Stack Frames 09:24 How Function Returns Adjust RSP 10:35 Stack Grows Downward in Memory 11:33 Program Setup ? Hybrid C++/Assembly 12:46 Assembly Module Overview 14:00 Function Prologue ? Register Push & Alignment 15:30 Allocating Stack Space for Local Array 17:45 Initializing Array in Loop 20:10 Printing Loop with printf 49:48 First Run ? Segfault Observed 51:00 16-Byte Stack Alignment Requirement 51:55 Fix 1 ? Extra Push/Pop in Prologue/Epilogue 53:15 Fix 2 ? Push/Pop Around Each printf Call 55:04 Testing Different Array Sizes 56:52 Debugging Alignment Behavior 58:54 Summary ? Creating Any Local Data on Stack 59:59 Closing Remarks & Subscribe Call =-=-=-=-=-=-=-=-= Thanks for watching! Find us on other social media here: https://www.NeuralLantern.com/social Twitter / X: https://x.com/NeuralLantern Rumble: https://rumble.com/c/c-3696939 BitChute: https://www.bitchute.com/channel/pg1P... Daily Motion: https://www.dailymotion.com/neurallan... Minds: https://www.minds.com/neurallantern/ Odysee: https://odysee.com/@NeuralLantern:5 Please show your support! Buy me a coffee: https://ko-fi.com/neurallantern Subscribe + Sharing on Social Media Leave a comment or suggestion Subscribe to the Blog: https://www.NeuralLantern.com Watch the main "pinned" video of this channel for offers and extras