Does the processor use more than one stack to separate the call stack from the expression/register stack?

257 Views Asked by At

I was reading some basic articles about memory manipulation by the processor, and I was confused as to how the processor handles what comes next.

The concept of the call stack is clear, but I was wondering if the expression stack/register stack (used to make the calculations) is the same stack, or even if the stack for the local variables of a subroutine (a function) in a program is the same call stack.

If anyone could explain to me how the processor operates regarding its stack(s), that'd help me a lot.

2

There are 2 best solutions below

0
On BEST ANSWER

All the processors I've worked on have just used a single stack for these.

If you think about what the processor is doing, you only need a single stack. During calculations you can use the same stack as the calling stack, as when the calculation is complete the stack will be 'clean' again. Same for local variables, just before you go out of the scope of the local variables your stack will be clean allowing the call to return correctly.

0
On

You can change the stack just set the SS:SP segment and pointer registers (just save the current values) The procedure call parameters and local variables takes place in the stack. And the dynamically created objects take place in the heap (DS:DI). The SS:SP register pair shifted by the right amount of bytes to reserve the needed memory on the procedure call. And on the return the SS:SP sets back to the pre call state.