in CO and Architecture edited by
91 views
0 votes
0 votes

 Please Explain : “ sp content is incremented for stack going downward method and decrement for stack going upward method”  

in CO and Architecture edited by
91 views

1 Answer

0 votes
0 votes
"The register that holds the address for the stack is called a stack pointer (SP)"

Depending on the environment the code is compiled in, the stack may 'grow' downward or upward. "Growing" the stack/heap simply means allocating memory from the stack/heap space for the program that requested it. In other words, SP may go from High address to Low address (Growing Downwards) or Low address to High Address (Growing Upwards) depending on the environment.

According to the question, we are performing a 'POP' operation (with SP = 5926).

So, If the stack does downwards:
High Address to Low Address, we get (5926 + 2) = 5928

If the stack does upwards:
Low Address to High Address, we get (5926 - 2) = 5924

More Explanation: https://www.youtube.com/watch?v=pOOivAJ63DM

3 Comments

@felix59

My question is why in downwards , 5926 + 2 is done, why not -2 is done.

 

0
0
'Downwards' indicates the direction the stack grows in. High to Low.

Consider this scenario, You have a stack that grows with downward-technique (From High memory location to Low memory location)

So it would look something like this:
The bottom of the stack would be at (suppose): 2044
The top of the stack at: 2012

The bottom of the stack is at a higher memory location because this stack grows in the downward direction.
No, suppose we apply a pop operation on the stack. This would update the stack as follows:

The top of the stack after POP: 2014

(2012 - 2014) = -2
Because when we pop, the SP will move toward the bottom of the stack.
1
1

@felix59 thanks

0
0

Related questions