69,382
社区成员
发帖
与我相关
我的任务
分享
# include <stdio.h>
int main (void)
{
int var1;
int var2;
int var3;
printf ("%10s%15s\n", "variable", "address");
printf ("%10s%15p\n", "var1", &var1);
printf ("%10s%15p\n", "var2", &var2);
printf ("%10s%15p\n", "var3", &var3);
return 0;
}
As to the historic rationale, I can't say for certain (because I didn't design them). My thoughts on the matter are that early CPUs got their original program counter set to 0 and it was a natural desire to start the stack at the other end and
grow downwards, since their code naturally grows upward.
Note that this setting of the program counter to 0 on reset is not the case for all early CPUs.
One of the first things some historical CPUs would do would be to scan memory from the top until it found a location that would read back the same value written, so that it would know the actual RAM installed (e.g., a z80 with 64K address space didn't necessarily have 64K or RAM, in fact 64K would have been massive in my early days). Once it found the top actual address, it would set the stack pointer appropriately and could then start calling subroutines.
http://stackoverflow.com/questions/2035568/why-do-stacks-typically-grow-downwards
x86 down
SPARC in a circle, very clever architecture, see below.
PPC down, I think.
System z in a linked list, I kid you not.
(but still down, at least for zLinux).
ARM selectable (thanks, Michael Burr).
Mostek6502 down (but only 256 bytes).
RCA1802A any way you want, subject to SCRT implementation.
PDP11 down.
来自
http://stackoverflow.com/questions/664744/what-is-the-direction-of-stack-growth-in-most-modern-systems/664779#664779