[Verse 1] When your program needs to call a function far away The CPU must save its state before it goes to play Push the return address right onto the stack So when the function's done, it knows just how to get back [Chorus] Stack it up, stack it down Parameters flying all around Calling conventions keep it clean Best assembly you've ever seen Push and pop, call and ret Stack-based communication, don't forget [Verse 2] Parameters travel different ways depending on the rule System V or Windows calling, each one has its tool Registers hold the first few args, the rest go on the stack Right to left they're pushed down tight in a parameter pack [Chorus] Stack it up, stack it down Parameters flying all around Calling conventions keep it clean Best assembly you've ever seen Push and pop, call and ret Stack-based communication, don't forget [Bridge] Caller saves or callee saves Who protects the register waves? EAX holds the return value tight While ESP keeps the stack frame right Function prologue sets the scene Epilogue keeps memory clean [Verse 3] The base pointer marks our frame, a reference we can trust Local variables live below in memory we adjust When the function's work is done, restore the stack with care Clean up parameters passed, leave nothing hanging there [Chorus] Stack it up, stack it down Parameters flying all around Calling conventions keep it clean Best assembly you've ever seen Push and pop, call and ret Stack-based communication, don't forget [Outro] From caller down to callee The stack connects them perfectly Function calls in harmony That's systems engineering mastery
← The Stack and Stack Operations | Bit Manipulation and Logical Operations →