> How did you call a function if you didn’t have a stack for the return address or local variables? Here’s how it worked. First, the compiler defined a secret global variable for each inbound function parameter, plus another secret global variable for each function to hold the return address. It also defined a secret global variable for each of the function’s local variables. I always assumed that functions did somet…
Yes they do. Depending on the architecture, there's either a stack pointer register and CALL/PUSH/POP instructions, or a general purpose auto-increment/decrement addressing mode. Local variables are placed on the stack as well, this is necessary if you want recursion, and it also typically results in faster/shorter code, because the instruction set and microarchitecture are optimized for this type of memory access.
Re: Subroutine calls in the ancient world, before computers had stacks or heaps
#241Thank you!