1
$\begingroup$

Professor said that modern processor needs runtime stack.

But he didn't explain the reason.

Why is the runtime stack required in the modern processors?

$\endgroup$
  • 4
    $\begingroup$ Best ask them. $\endgroup$ – Raphael Oct 21 '17 at 16:19
5
$\begingroup$

I would say that "required" is a bit of strong word. Processors provide hardware support for stacks to help implement the call stack abstraction. Having special instructions to do so can improve performance. Note however that some processors like ARM (except in Thumb mode) do not really have special instruction to do so, the ldm/stm instructions with pre/post inc/dec are flexible enough to do so.

$\endgroup$
1
$\begingroup$

Stacks are quite useful for running software. There is no reason why stacks would need to be part of processor. For example, the POWER architecture does not have a call stack as part of the processor. All it has is an architecture that jumps to one address while storing the address following the branch instruction in a special purpose register. ONE special purpose register. No stack.

$\endgroup$
1
$\begingroup$

There are several aspects.

  • Processors meant to execute most common languages (such as C) need to implement efficiently stacks for parameters passing and call/return addresses. Some of that stack is usually replaced by registers, for efficiency (using registers for passing parameters to subroutines, link register ...), but when registers are not sufficient, processors typically feature instructions for pushing and popping parameters from the stack (x86 PUSH/POP, auto increment/decrement memory access instructions, ...)

  • From a software point of view, the stack is a place in memory. Accessing memory (typically in cache) for all these data transfers can induce latency and power draw. Some advanced CPUs have special memories and bypassing to avoid cache accesses for parameters and return addresses.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.