Registers
Intel x86 32bit registers

r stands for 64 bits, e stands for 32 bits.

How function call works in assembly
Firstly, we put arguments in reverse order. (push $2, push $1)
$for denoting literal.Push the current instruction pointer on the stack, and then the %eip is pointed to the start of the new function.
call calleeThen, we put the base pointer value on stack. We copy esp value to ebp. The compiler already knows how much space is needed for the local variable of callee, we subtract this much from the stack pointer. These new values of ebp and esp form new stack frame. (push %ebp, mov %esp %esp, ).
From here we start allocating spaces for variables,
int localin this case. sub $4 %espAt the end we put return value back in eax. mov $42, %eax
After the function is done, we move the stack pointer back to the base of the current function stack. The local variable space is not deallocated, but it will be overridden when we want to call the next function. This saves us time . mov %ebp, %esp
Then we pop the next value from the stack, which is like the EBP of caller function, into the EBP register.
retIt saves; it pops the next value from the stack, which is the EIP of the previous function where we left off, and it is put back into the EIP register.We move the stack pointer to move the arguments from the current stack frame.add $8, %esp

System v ABI
The System V AMD64 ABI (Application Binary Interface) is the standard calling convention for x86-64 processors on Unix-like operating systems, including Linux, macOS, FreeBSD, and Solaris. It specifies how functions receive parameters, how they return values, and how the stack is managed during execution.
Unlike 32-bit x86 conventions that passed most arguments on the stack, the System V AMD64 ABI uses registers for the first several arguments to improve performance. %rdi, %rsi, %rdx %rcx %r8 %r9.
Floating-Point Arguments: The first eight are passed in SSE registers: %xmm0 through %xmm7. Excess Arguments: Any additional arguments beyond these are passed on the stack in reverse order (right-to-left). Variadic Functions: For functions like printf, the %al (low byte of %rax) register must hold the number of SSE registers used to pass arguments
Return Values
Integers & Pointers: A single value up to 64 bits is returned in
%rax. If a value is 128 bits, the higher 64 bits are returned in%rdx.Floating-Point: Values are returned in
%xmm0(and%xmm1if necessary).Large Structures: If a return value is too large to fit in registers, the caller allocates memory and passes a hidden pointer to that memory in
%rdias the first argument.
**Register Preservation (Callee vs. Caller Saved) **


Links
https://godbolt.org/, compiled instructions in assembly.
https://docs.google.com/presentation/d/11-AQr9T04TikHhcyijJTv7AjNy5_5cTvkn_mEw1Q4A4/edit?slide=id.g150f76b9c85_0_1538#slide=id.g150f76b9c85_0_1538 X86 instruction set and calling convention.