Sign in

Not a member? | Forgot your Password?

Search Comp.Arch.Embedded

Search tips

Free PDF Downloads

Advanced Linux Programming

What Every Programmer Should Know About Memory

Introduction to Embedded Systems

C++ Tutorial

Embedded Systems - Theory and Design Methodology

Microcontroller Programming and Interfacing

Introduction to Microcontrollers


More Free PDF Downloads

Recent Blogs on EmbeddedRelated

Important Programming Concepts (Even on Embedded Systems) Part III: Volatility
posted by Jason Sachs


Ada - 7 Segments and Catching Errors
posted by Mike Silva


Project Directory Organization
posted by Stephen Friederichs


OOKLONE: a cheap RF 433.92MHz OOK frame cloner
posted by Fabien Le Mentec


Practical protection against dust and water (i.e. IP protection)
posted by Dr Cagri Tanriover


Introduction to Microcontrollers

1 - Beginnings

2 - Further Beginnings

3 - Hello World

4 - More On GPIO

5 - Interrupts

6 - More On Interrupts

7 - Timers

8 - Adding Some Real-World Hardware

9 - More Timers and Displays

10 - Buttons and Bouncing

11 - Button Matrix & Auto Repeating

12 - Driving WS2812 RGB LEDs

13 - 7-segment displays & Multiplexing

See Also

ElectronicsDSPFPGA

Discussion Groups | Comp.Arch.Embedded | Direction of Stack Growth

There are 180 messages in this thread.

You are currently looking at messages 1 to 10.


So far in October, you have voted 0 times ou of a total of 0 votes by the community.
Please help us clean the archives from unuseful discussion threads by using the voting system! Details here.

Direction of Stack Growth - karthikbalaguru - 2007-10-21 07:44:00

Hi,

Why some processors have stack growing downwards and others have stack
growing upwards ?
Any advantages/disadvantages w.r.t both these designs.
Which is the best model ?

I serached the internet, but i did not find a good link that explains
these stuffs in detail.

Thx in advans,
Karthik Balaguru


Re: Direction of Stack Growth - Jerry Avins - 2007-10-21 12:41:00

karthikbalaguru wrote:
> Hi,
> 
> Why some processors have stack growing downwards and others have stack
> growing upwards ?
> Any advantages/disadvantages w.r.t both these designs.
> Which is the best model ?
> 
> I serached the internet, but i did not find a good link that explains
> these stuffs in detail.
> 
> Thx in advans,
> Karthik Balaguru

In the beginning, it was customary to start a peogram at or near the 
bottom of memory and start the return stack at or near the top. That 
allowed the largest amount of RAM for stack space. When there are two 
stacke, it is usual to make one grow down andthe other grow up and then 
to hope that they never meet.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Re: Direction of Stack Growth - Tim Wescott - 2007-10-21 12:41:00

On Sun, 21 Oct 2007 04:44:30 -0700, karthikbalaguru wrote:

> Hi,
> 
> Why some processors have stack growing downwards and others have stack
> growing upwards ?
> Any advantages/disadvantages w.r.t both these designs.
> Which is the best model ?
> 
> I serached the internet, but i did not find a good link that explains
> these stuffs in detail.
> 
> Thx in advans,
> Karthik Balaguru

I don't think it makes a big difference one way or another.  After a
designer has decided where to vector the program counter on reset, and
where to put the interrupt vector table, there may be some slight
advantage.

But mostly I think the decision is arbitrary.

-- 
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html

Re: Direction of Stack Growth - Everett M. Greene - 2007-10-21 12:43:00

karthikbalaguru <k...@gmail.com> writes:

> Why some processors have stack growing downwards and others
> have stack growing upwards?

Tradition.

> Any advantages/disadvantages w.r.t both these designs?

Not especially.

> Which is the best model?

Your choice.

> I serached the internet, but i did not find a good link
> that explains these in detail.

There are some processors that can't perform negative offset
indexing in which case an upward-growing stack is awkward to
program.

Re: Direction of Stack Growth - Thad Smith - 2007-10-21 13:04:00

karthikbalaguru wrote:

> Why some processors have stack growing downwards and others have stack
> growing upwards ?
> Any advantages/disadvantages w.r.t both these designs.
> Which is the best model ?

Obviously either works.  One old trick for allocating a memory block 
between two different uses when you don't know the amount needed before 
hand is to start allocating one from the bottom of the block and start 
allocating the second from the top of the block and allow the two 
increasing blocks to grow towards each other.  This allows total use of 
the memory block without knowing the individual sizes in advance.

Allocating the stack from the top down is sometimes used in conjunction 
with allocating heap storage from the bottom up within the same memory 
block.

-- 
Thad

Re: Direction of Stack Growth - Grant Edwards - 2007-10-21 13:57:00

On 2007-10-21, karthikbalaguru <k...@gmail.com> wrote:

> Why some processors have stack growing downwards and others
> have stack growing upwards ?

The designers had different preferences.

> Any advantages/disadvantages w.r.t both these designs.

Not really.

> Which is the best model ?

The one that's supported by your CPU. :)

-- 
Grant Edwards                   grante             Yow!  Yow! Are we wet yet?
                                  at               
                               visi.com            

Re: Direction of Stack Growth - John L - 2007-10-21 15:48:00

> In the beginning, it was customary to start a peogram at or near the
> bottom of memory and start the return stack at or near the top.

Beginning of what?  The earliest computer I used that had hardware
stack support was the PDP-6, designed circa 1963, and its stacks grew
upwards.  The B5000 which was designed around the same time or
slightly earlier also had upward growing stacks.

I see two motivations for the switch in modern computers to stacks
that grow downward.  One was the use of programming techniques that
used heap storage in a fixed address space, which made it attractive
to have the heap and stack grow toward each other.  (Back in the 60s
memory was so valuable that you laid it all out when you wrote your
program, and the stack was just one of the areas you laid out.)

The other is the influence of the IBM S/360.  Its desigers didn't put
in explicit stack hardware because they knew it was easy to do a stack
in software if you have base and index registers.  But its addressing
modes have a 12 bit unsigned offset that is added to the base
register.  If a stack grows upward, a program either needs a frame
register separate from the base register to address local variables,
or else use extra instructions to simulate negative offsets.  If the
stack grows down, locals are at positive offsets from the stack
pointer.  Most (all?) modern computers have signed offsets so it'd
work either way, but once you're used to a programming style, why
mess with it?



Re: Direction of Stack Growth - glen herrmannsfeldt - 2007-10-21 16:30:00

Jerry Avins wrote:
> karthikbalaguru wrote:

>> Why some processors have stack growing downwards and others have stack
>> growing upwards ?
(snip)

> In the beginning, it was customary to start a peogram at or near the 
> bottom of memory and start the return stack at or near the top.

I thought of that, but I didn't see why programs couldn't
load at the top and the stack grow from the bottom.
I suppose, though, that it helps not to need to do relocation,
if the load point is always the same.

This is all without virtual storage (dynamic address translation),
and a single task (no need to leave memory for anyone else).

> That 
> allowed the largest amount of RAM for stack space. When there are two 
> stacke, it is usual to make one grow down andthe other grow up and then 
> to hope that they never meet.

-- glen


Re: Direction of Stack Growth - Hans-Bernhard Bröker - 2007-10-21 16:38:00

karthikbalaguru wrote:

> Why some processors have stack growing downwards and others have stack
> growing upwards ?

Because they can.

> Which is the best model ?

Neither.  If there were one that was "the best", just like that, the 
other would probably no longer be around.

Re: Direction of Stack Growth - Randy Yates - 2007-10-21 17:09:00

glen herrmannsfeldt <g...@ugcs.caltech.edu> writes:

> Jerry Avins wrote:
>> karthikbalaguru wrote:
>
>>> Why some processors have stack growing downwards and others have stack
>>> growing upwards ?
> (snip)
>
>> In the beginning, it was customary to start a peogram at or near the
>> bottom of memory and start the return stack at or near the top.
>
> I thought of that, but I didn't see why programs couldn't
> load at the top and the stack grow from the bottom.
> I suppose, though, that it helps not to need to do relocation,
> if the load point is always the same.
>
> This is all without virtual storage (dynamic address translation),
> and a single task (no need to leave memory for anyone else).
>
>> That allowed the largest amount of RAM for stack space. When there
>> are two stacke, it is usual to make one grow down andthe other grow
>> up and then to hope that they never meet.
>
> -- glen

My experience (which dates from about 1978) supports your observations
and Jerry's original explanation.
-- 
%  Randy Yates                  % "Remember the good old 1980's, when 
%% Fuquay-Varina, NC            %  things were so uncomplicated?"
%%% 919-577-9882                % 'Ticket To The Moon' 
%%%% <y...@ieee.org>           % *Time*, Electric Light Orchestra
http://www.digitalsignallabs.com

| 1 | | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |