Nios/callsave

From ASMBits

Write a function with four parameters named call1234 that calls the function secret with four parameters with values 1, 2, 3, and 4. It should return how many of its four original parameters are equal to the return value of secret(1,2,3,4). Since there are 4 parameters, call1234 will only ever return 0 through 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 (int a, int b, int c, int d) {
    n = secret(1,2,3,4);
    return (How many of {a, b, c, d} are equal to n);
}

Recall that the first 4 parameters to a function are passed through registers r4 through r7. The purpose of this problem is to exercise saving and restoring registers. You need to use the (caller-saved) function parameters passed to you, yet you must reuse the same registers to pass parameters to a function you call.

Expected solution length: Around 30 lines.

Sample Input

call1234(10,10,20,30)

Sample Output

2, if secret(1,2,3,4) returns 10

Write your solution here

Upload a source file...