0 votes
in General Knowledge by (744k points)
How do you set up the program stack?

1 Answer

0 votes
by (744k points)
Best answer
At program start:

1) Set %rbp to point to the bottom of the current stack frame.
pushq %rbp (the caller's base pointer is now saved)

2) Set %rsp to point at the top of the stack (same address as the stack bottom initially)
movq %rsp, %rbp (set base pointer, stack is now empty)

At the end of a function:

3) Put them back
leave (set caller's stack frame back up, this goes right before ret)
Welcome to the Answerine , a great place to find, read and share your favorite questions and answers.