detail implementation of function invocation
the question was a good answer at the time, but many of the details were not clear. So the following disassembly of a small program, for analysis, because I am more familiar with the arm assembly, so I chose a cross toolchain installed Ubuntu, and did not use the previous CentOS. So maybe the wind will be a little different.
I wrote a simple program and makefile. The fun () function is called by the main function in the program.
Compile the program, generate the executable file, and disassemble it, write the post-disassembly information to the dump file, open the dump file, and analyze the key source code.
You can see that the procedure for a function call is as follows:
1. Pass the parameter, if the parameter is less than four, then use R0-R3 4 registers to pass, the excess 4 passes through the compression stack transmission, but the pressure stack chooses the pressure variable e instead of chooses the pressure variable A, then indicates that the pressure stack is from right to left.
2. Use the jump command to jump to the corresponding function segment.
3. Increase the stack frame, save the current stack base-point pointer FP, and then re-assign the new value to the stack base pointer FP and the top pointer sp.
4. Save the parameters passed in the register into the stack.
From for notes (Wiz)
Detail implementation of function invocation