0

IIRC it should be high->low,but according to this image,it's low->high.

enter image description here

I'm now confused,which is the case?

Seems the code is also executed from low->hight:

0x0000000000400498 <main+0>:    push   %rbp
0x0000000000400499 <main+1>:    mov    %rsp,%rbp
0x000000000040049c <main+4>:    sub    $0x10,%rsp
0x00000000004004a0 <main+8>:    movl   $0x6,-0x4(%rbp)
assem
  • 3,023
  • 4
  • 20
  • 20
  • 1
    It really depends on what "system" you are talking about - you need to be a *lot* more specific, e.g. architecture, OS, ABI and also what context you're talking about, such as stack allocations, heap allocations, linker static/global allocations, etc. From the diagram I'm guessing you're talking about stack allocations on x86 ? – Paul R Mar 28 '11 at 07:56
  • possible duplicate of [How will you find out if a stack grows up or down in a system ?](http://stackoverflow.com/questions/5361123/how-will-you-find-out-if-a-stack-grows-up-or-down-in-a-system) – Paul R Mar 28 '11 at 08:32

1 Answers1

2

On Intel x86/x64, which are the most popular architectures that run Windows, the stack "grows" towards the lower addresses. I.e., pushing onto the stack involves subtracting from the stack pointer (ESP), and popping from the stack involves adding to the stack pointer.

The stack grows from the top to the bottom in your example. This is the function's prologue, and it uses the SUB instruction to allocate stack space for local variables. You might be confusing the stack with the memory in which your program is stored -- in that area, the CPU executes instructions sequentially, from low to high addresses, until a branch (e.g. JMP) instruction is encountered.

Sasha Goldshtein
  • 3,499
  • 22
  • 35