Arm/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
    ldr sp, =0x40000000 // Initial sp
4
    mov r0, #2
5
    mov r1, #1
6
    mov r2, #2
7
    
8
    bl sum
9
    1: b 1b  // done
10
11
.global sum
12
sum:
13
    
14
    
Upload a source file...