Parameter transfer during vdsp function calling

Source: Internet
Author: User

Development Environment: Vdsp 5.0 1. function call when no parameter existsVoid sub (void) {} void func (void) {sub (); // call sub;} This is the simplest function to call. Call directly, there is no other processing. Processing When 2 <= 3 parametersVoid sub (int A, int B, int c) {// link 0x0; // [FP + 0x10] = R2; // [FP + 0xc] = R1; // [FP + 0x8] = R0; // unlink;} void func (void) {// link 0xc; sub (1, 2, 3); // r2 = 3; // R1 = 2; // R0 = 1; // call sub;} from the above code, we can see that, when the number of parameters is less than or equal to three, vdsp uses r0, R1, and R2. From the code above, we can see that the stack space of function parameters is allocated by the calling function (func), which is also the reason why the function uses link 0xc to reserve 12 bytes of stack space. Note that, even if the sub function does not have a parameter, func reserves 12 bytes of stack space. The reason for saving the parameter from [FP + 0x8] Is that the link command will import the rets and FP registers into the stack, so that the SP increases by 8 bytes down. 3> processing of three parametersVoid sub (int A, int B, int C, int D, int e) {// R3 = [FP + 0x14]; // R7 = [FP + 0x18]; // [FP + 0x18] = R7; // [FP + 0x14] = R3; // [FP + 0x10] = R2; // [FP + 0xc] = R1; // [FP + 0x8] = R0;} void func (void) {sub (1, 2, 3, 4, 5); // p1 = 5; // [SP + 0x10] = p1; // p1 = 4; // [SP + 0xc] = p1; // r2 = 3; // R1 = 2; // R0 = 1; // call sub;} the preceding Code shows that, vdsp writes parameters from right to left into the stack, and then calls the sub-function. The sub-function directly uses the data in the stack. 4. Processing when the number of parameters does not matchVoid func (void) {sub (1, 2, 3, 4, 5); // p1 = 5; // [SP + 0x10] = p1; // p1 = 4; // [SP + 0xc] = p1; // r2 = 3; // R1 = 2; // R0 = 1; // call sub ;} void sub (int A, int B) {// [FP + 0xc] = R1; // [FP + 0x8] = R0;} in the C compiler, the number of real parameters in the form does not match. Only a warning is given. From the code above, we can see that both the called and called functions are processed based on the parameters we see. In this way, when the number of real parameters is less than the number of tangible parameters, it is almost certainly an error! Because the sub-function cannot obtain the correct parameter value. 5. return valuesInt sub (int A, int B) {return a-B; // R0 = R0-r1 (NS); // unlink; // RTS;} void func (void) {int A; A = sub (5, 3); // R1 = 3; // R0 = 5; // call sub; // [FP + 0x8] = R0;} It is easy to see from the assembly code above that vdsp uses R0 to save the return value.

 

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.