The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+21 votes
3.3k views

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
asked in CO & Architecture by Veteran (59.6k points)
recategorized by | 3.3k views
+1

option (A) should be "It can not have subroutine call instruction"

reference @ http://gateforum.com/wp-content/uploads/2013/01/CS-2001.pdf

–2
Not having SP means no stack too. So, can we not store the activation records, CS,IP etc values into heap, pass along with parameters(also in stack with some other register holding the current heap pointer and one variable pointing to previous activation record)
0
Could anybody tell which option is the answer please ?and why?
0
"not having stack pointer mean not having stack " its drastic conclusion , please shed some light here.
0

does not have any stack pointer registers

I am thinking can not we use any other register to work as stack pointer registers. or can not we use Heap are to achieve same functionality.

0
@Arjun sir I understand that we can have a subroutine call without having a stack pointer register as the return address gets stored in the stack. But how do we access return address for that subroutine call? And please explain why we cannot have nested subroutine calls.
+4
@Dharmendra Lodhi

we have to assume that there is no stack pointer register, So first of all what it means is, we have to understand what is the use of stack pointer, so i think we know that stack pointer points the top element of the stack but now the problem is what is stack here, so stack is nothing but memory stack, we will use some part of main memory as a stack, along that we know that there is no fixed size of stack in real implementation but here in some questions of GATE they have been used as some 100-200 bytes.So in order to keep track of what is the thing we have to push or pop, we generally use stack pointer registers.

So basically the question comes in mind that why we use memory stack right!! whenever we call any subroutine in our main program, we have to store the current PC and save the starting address of subroutine and execute the subroutine and then return to our main program. So I mean we have to store the return address somewhere so that after finishing code of subroutine, i can continue my main program.

So in order to store the return address, there are various other mechanisms too like;

1. Temporary  Register

2. Store the return address in the starting location of subroutine itself.

3. Fixed memory location (maybe at the starting location: 0000h)

4. Memory stack (It is the best one)

How stack pointer works in memory stack?? hope u are visualizing stack here

Suppose we are in the main program "A" and in the middle, there is some function has been done and we have to jump to the subroutine "B".So the first thing we need to do is, the instruction which is responsible for jumping to subroutine B,at that time when we fetch and decode that instruction, PC already got incremented, right!!!

M[SP]<--PC

SP++

PC<--- subroutine address ie; B

Execute the code of subroutine B

After finishing subroutine,

SP--

PC<--M[SP]

and by doing this we will get the return address means now we are in the normal mode of execution in our main program A.

This is how CALL instruction is implemented in general purpose processors.

Now coming back to this question;

A is False because we can implement CALL instruction via other mechanisms (like temporary register, storing address at fixed location etc..) but it is not efficient.

C is False because Interrupts can be possible in the same way as A option because interrupts also something that we have to execute the ISR and then come back to the normal flow of the program by storing a return address

D is  False because all subroutines and interrupts are not possible because there are some subroutines which can be implemented without memory stack(or stack pointer register) like A is calling B and in this case we can store the PC in the temporary register and after finishing the code of B, I can come back to A and start executing with the help of temporary register.

But if we call like this, from A to call B and then in the subroutine B, we are calling to C(nested subroutine), here we cannot execute this type by the temporary register, here we need stack and stack pointers

option B is correct
0
Explained very well. Thank you.
0

welcome!!! Sakshi Jaiswal

0

@akash

isnot C) also a possible answer?without stack how an interrupt possible?

https://gateoverflow.in/257653/vectored-or-non-vectored-interrupt#c257659

0

without stack how an interrupt possible?

BY DEDICATING ONE FIXED MEMORY ADDRESS ALWAYS FOR INTERRUPT HANDLING WE CAN DO THAT.

0
@srestha

I have already included ur answer in my comment..

5 Answers

+22 votes
Best answer

I think answer is B.

Because in nested subroutine calls we used to push old subroutines into stack and pointing most recent call with stack pointer.

answered by Loyal (8.3k points)
edited by
–1

@Arjun Sir. Could you please confirm this answer ?

I think, we can call the subroutine but subsequently we can not return back to the next instruction from where we left previously. But at the same time i am also getting that we may call nested subroutine also.

+1
How can we have subroutine call  ??
+9

Subroutine calls can still be possible using fixed memory location. Like one implementation says that we can use the first memory address of subroutine for storing the return address. But, nested calls won't be possible.

I think B is correct

Edit: Providing reference for one such implementation https://en.wikipedia.org/wiki/Subroutine#Jump_to_subroutine

+4

I think Option (A) has to be the answer because when the processor doesn't have any stack pointer register, it should also not have Instruction code written into its instruction set which is needed as an instruction to go forward with implementing subroutine calling, which causes the address of the subroutine to be pushed onto the stack.
The stress must be on the words of option A
"Subroutine call Instruction"

clearly when for any operation I don't have an instruction in instruction set, I cannot implement it.

0
What should be the addressing mode then??
0
He didn't said we don't have any stack but he said we don't have any stack pointer..

I guess without even stack pointer we can still enjoy all utilities of stack although it would be tedious and may be time consuming ...so i think answer should be D.
0
without stack pointer register we can not implement nested interrupts,..so D) can not be the answer
0
I think it should be D. We can implement a stack using an array or a LL and then use this stack for all such operations. Please correct me if I am wrong!
+14 votes

 A stack pointer is a small register that stores the address of the last program request in a stack.

And a nested function (or nested procedure or subroutine) is a function which is defined within another function, the enclosing function. So if there is no stack pointer register then No nested subroutine call possible, hence option B is correct.

answered by Veteran (70.3k points)
0
I think option D is also possible. We can implement a stack using an array or a LL and then use this stack for all such operations. Sir, please correct me if I am wrong!
+3 votes

It can not have subroutine call instruction ,

For 8085: Stack pointer is a special purpose 16-bit register in the Microprocessor, which holds the address of the top of the stack.

The most typical use of a hardware stack is to store the return address of a subroutine call. When the subroutine is finished executing, the return address is popped off the top of the stack and placed in the Program Counter register, causing the processor to resume execution at the next instruction following the call to the subroutine.

You push items onto the stack and pop them off. In a microprocessor, the stack can be used for both user data (such as local variables and passed parameters) and CPU data (such as return addresses when calling subroutines).

The actual implementation of a stack depends on the microprocessor architecture. It can grow up or down in memory and can move either before or after the push/pop operations.

Operation which typically affect the stack are:

  • subroutine calls and returns.
  • interrupt calls and returns.
  • code explicitly pushing and popping entries.
  • direct manipulation of the SP register.

http://stackoverflow.com/questions/1464035/what-is-a-stack-pointer-used-for-in-microprocessors

http://en.wikipedia.org/wiki/Call_stack

Necessary steps to implement a subroutine  The stack pointer register must be initiali zed ,preferably at the highest memory lo cation of the R/W memory.  The call instruction should be used in the main program accompanied by the RET i nstruction in the subroutine @ http://www.slideshare.net/safinbiswas/stack-in-microprocessor-8085presantation

answered by Loyal (6.1k points)
reshown by
+4
Good explanation. But this says subroutine calls are implemented using stack. This doesn't say without stack we cannot implement subroutine calls, rt?
0

Necessary steps to implement a subroutine  The stack pointer register must be initiali zed ,preferably at the highest memory lo cation of the R/W memory.  .... is not enough sir ??

+1
Nopes. Because that sentence assumes a "stack implementation".

To say A is the answer we have to prove, there is no way to implement subroutine calls without a stack.
+1
so answer is B ??  need more expln ....
0
Yes. And the explanation would be a solution to implement subroutine without a stack. I'll add it.
0
Can't we use any general purpose register as stack pointer register, then we have to manually perform push and pop operation?
0
I think answer should be B) because we won't be able to use stack but "link register" is another option which can store single return address
0
@Arjun sir,

Why are we having b as answer and not a?

Please confirm if b is the correct answer.
0

@rahul sharma 5 

 A stack pointer is a small register that stores the address of the last program request in a stack.

A nested function (or nested procedure or subroutine) is a function which is defined within another function, the enclosing function.  It means if we don't store last program request then how nested function works ?

So if there is no stack pointer register then No nested subroutine call possible, hence option B is correct.

0 votes
I think we can always use stack using a memory location for stack pointer instead of using register. Ans is D.
answered by (37 points)
–1 vote

Explanation: Stack pointer register hold the address of top of stack, which is the location of memory at which CPU should resume its execution after servicing some interrupt or subroutine call.

So if SP register is not available then no subroutine call instructions are possible. So (A) is correct option.

http://quiz.geeksforgeeks.org/gate-gate-cs-2001-question-10/

answered by Junior (693 points)
0

So if SP register is not available then no subroutine call instructions are possible. So (A) is correct option.

How nesting then work if you don't save address of next instruction ?

0
@Bikram sir what is wrong with option (c)?
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,515 questions
48,528 answers
155,019 comments
63,372 users