1
$\begingroup$

Suppose a processor does not have any stack pointer registers, which of the following statements is true?

  1. It cannot have subroutine call instruction
  2. It cannot have nested subroutines call
  3. Interrupts are not possible
  4. All subroutine calls and interrupts are possible

====================================================================

I think answer is 2.

Reason- Because in nested subroutine calls, we push old subroutines into stack and point most recent call with stack pointer.

Please, explain which is the correct option. According to book the answer is 1.

$\endgroup$
2
$\begingroup$

Depends on how exactly you define "stack pointer", "subroutine" and "nested subroutine" (I presume the latter means recursion).

If you disallow recursion you don't need a stack. To store your local variables and parameters you instead statically allocate space for them. They basically become globals. As long as you don't need to enter the same subroutine again there will be no problem.

And when you call the subroutine you pass along the return address as a (hidden) parameter and instead of return you jump to that return address. Stack-based call and ret instructions do this automatically pushing the next instruction address to the stack followed by jump and popping the return address followed by the jump resp.

Interrupts are in the same boat, except for how to automatically forward the resume address to the handler. One way is to hardcode a memory location or register for that.

$\endgroup$
2
$\begingroup$

The Control Data Cyber series had no stack pointer, but it had a Pascal compiler. Seymour Cray says your book is wrong. (The Subroutine Call instruction that this computer isn’t supposed to have would store the return address into the location after the instruction it branched to, forming an instruction that could be used to jump back to the caller). If your instructor doesn’t know who Seymour Cray is then they shouldn’t be teaching.

And there were microprocessors that handled interrupts by switching to a second set of registers. So the answer would be 4.

$\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.