GCC compiles (using gcc --omit-frame-pointer -s):
int the_answer() { return 42; }
into
.Text .globl _the_answer _the_answer: subl $12, %esp movl $42, %eax addl $12, %esp ret .subsections_via_symbols
What is the ‘$12’ constant doing here, and what is the ‘%esp’ register?
Short answer: stack frames.
Long answer: when you call a function, compilers will manipulate the stack pointer to allow for local data such as function variables. Since your code is changing
esp, the stack pointer, that’s what I assume is happening here. I would have thought GCC smart enough to optimize this away where it’s not actually required, but you may not be using optimization.