Detail implementation of function invocation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.