Nios/sum args

From ASMBits

Write a function with a variable number of arguments that returns the sum of all of its arguments. The first argument n tells you how many numbers to sum. The remaining n integers are the numbers to sum. The function will be called with exactly n+1 arguments.

Return the sum of all n numbers. Overflowing a 32-bit register should wrap around (i.e., no special handling).

int sum (int n, ... );

Expected solution length: Around 15 lines.

Sample Input

sum(2, 1, 2)

Sample Output

 3 

Write your solution here

x
 
1
.global _start
2
_start:
3
    movia sp, 0x04000000    # Initial sp
4
    movia r4, 2
5
    movia r5, 1
6
    movia r6, 2
7
    
8
    call sum
9
    1: br 1b  # done
10
11
.global sum
12
sum:
13
    
14
    
Upload a source file...