Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Why are variables stored on the stack?

Thread Tools

Why are variables stored on the stack?

Barry Schwarz
Posts: n/a
On Mon, 31 Mar 2008 04:27:45 GMT, David Thompson
<(E-Mail Removed)> wrote:

>#if offtopic = further and further
>On Mon, 17 Mar 2008 15:06:15 -0400, Removed) wrote:
>> jacob navia <(E-Mail Removed)> wrote:

><snip: S/360 et seq example of unusual auto/local-space handling>
>> > The documentation goes on to specify that register 13 (R13) is used to
>> > address this memory.

>> That's all correct, but you've misunderstood it. While R13 does point
>> to the current "stack frame" (which is a bit of a misnomer, most
>> computer scientists would use the term "activation record" instead),
>> those "stack frames" are *not* stored contiguously in memory. Rather,
>> they are allocated individually (from the heap) and chained together
>> into a doubly-linked list in a LIFO fashion. Thus, R13 is not simply
>> incremented and decremented on entry and exit like a traditional stack
>> pointer, but is rather saved and restored like the other registers. <snip>

>Do you really mean doubly-linked? It would make no sense to link both
>directions (logically 'up' and 'down'). Some _other_ languages with
>nested routines (notably PL/I) require both dynamic (call) and static
>('lexical') links, but that's not what I normally call doubly-linked.

Yes it is doubly linked. The first 72 bytes of the area pointed to by
R13 are reserved for saving and restoring registers. In both 24 and
31 bit addressing modes, bytes 4 through 7 contain the address of the
area that belongs to the function that called the current function. In
that area, bytes 8 through 11 point to the area that belongs to this
function. Things are a bit more complicated in 64 bit addressing

And it does make sense, for reasons which are even more off topic.

Remove del for email
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? C++ 9 03-23-2008 04:03 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
where are session variables stored on client DC Gringo ASP .Net 7 01-03-2005 07:59 AM
Where are JSP session variables stored? Steve Sobol Java 6 09-05-2004 04:20 PM