I wanted to see how std::atomic is translated to assembly. To do that I wrote the following code but there is something I do not understand.
The following code:
int main(void)
{
std::atomic<int> a;
a.fetch_add(0);
return 0;
}
Is compiled by GCC to:
1 | push rbp
2 | mov rbp, rsp
3 | mov DWORD PTR [rbp-4], 0
4 | mov DWORD PTR [rbp-8], 5
5 | mov edx, DWORD PTR [rbp-4]
6 | lea rax, [rbp-12]
7 | lock xadd DWORD PTR [rax], edx
8 | mov eax, 0
9 | pop rbp
10| ret
Why does GCC push "5" (on line 4) onto the stack?