As far as I know, when a process allocates local variables, it does so by pushing them onto memory as a stack, but still accesses them as random memory by using an offset from the stack pointer to reference them (from this thread [What is the idea behind using a stack for local variables?](https://stackoverflow.com/questions/26898040/what-is-the-idea-behind-using-a-stack-for-local-variables)).

However, how does it know which variables have what offset? Am I thinking about this in the right way?