Arm/callparam

From ASMBits

Write a function named call1234 that calls the function secret with four parameters with values 1, 2, 3, and 4. It should return the result of secret(1,2,3,4). The function secret is provided for you: Your submitted code should not contain that function, or you will end up calling your version rather than the one that is provided for you.

int call1234 () {
    return secret(1,2,3,4);
}

Recall that the first 4 parameters to a function are passed through registers r0 through r3. Also don't forget to save lr, as the function call will clobber it. (See Hint for an alternative method).

Expected solution length: Around 8 lines.

Sample Input

No input

Sample Output

1

One optimization that can be done to functions whose last action is to return the result of a function call is to set up the function parameters, then use a standard branch (rather than branch-and-link) to call the function. Because you didn't use branch-and-link, the function you "called" will directly return to your caller, which reduces the number of function return instructions executed. This optimization is called tail call elimination.

Using tail call optimization in this problem also allows you to avoid saving and restoring the link register.

Write your solution here

Upload a source file...