Search⌘ K
AI Features

Function and Stack

Explore how function parameters are passed using registers and stack in x64 Linux systems. Learn to analyze the stack frame layout, understand the function prolog and epilog sequences, and observe how local variables are managed in memory during function execution.

FunctionParameters project

Let’s discuss how a caller function passes its parameters via registers, as well as how a callee (the called function) accesses them.

Here is the project source code:

C++
// FunctionParameters.cpp
int arithmetic (int a, int b);
int main(int argc, char* argv[])
{
int result = arithmetic (1, 1);
return 0;
}
// Arithmetic.cpp
int arithmetic (int a, int b)
{
b = b + a;
++a;
b = b * a;
return b;
}

Stack structure

Remember the %RBP registers used to address stack memory locations? Here we provide a typical example of the stack memory layout for the ...