sum.ssa (608B)
1 # Simple test for addressing modes. 2 3 export 4 function w $sum(l %arr, w %num) { 5 @start 6 @loop 7 %n1 =w phi @start %num, @loop1 %n2 8 %s0 =w phi @start 0, @loop1 %s1 9 %n2 =w sub %n1, 1 10 %c =w cslew %n1, 0 11 jnz %c, @end, @loop1 12 @loop1 13 %idx0 =l extsw %n2 14 %idx1 =l mul 4, %idx0 15 %idx2 =l add %idx1, %arr 16 %w =w loadw %idx2 17 %s1 =w add %w, %s0 18 jmp @loop 19 @end 20 ret %s0 21 } 22 23 # >>> driver 24 # extern int sum(int *, int); 25 # int arr[] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 }; 26 # #define N sizeof arr / sizeof arr[0] 27 # int main() { 28 # int i, s; 29 # for (s=i=0; i<N; i++) s+=arr[i]; 30 # return !(sum(arr, N) == s); 31 # } 32 # <<<