Does the system allocates memory from high->low or the reverse?
IIRC it should be high->low
,but according to this image,it's low->high
.
I'm now confused,which is the case?
Seems the code is also executed from low->hight
:
0x0000000000400498 <main+0>: p开发者_C百科ush %rbp
0x0000000000400499 <main+1>: mov %rsp,%rbp
0x000000000040049c <main+4>: sub $0x10,%rsp
0x00000000004004a0 <main+8>: movl $0x6,-0x4(%rbp)
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.
精彩评论