Hello everyone,
I am using a C6000 DSP and I am trying to do a nested for like the next code but in assembly language
for (j=0,j< it2, j++)
{
y [ j*it ]=0;
for (i=1;i<it,i++)
{
y [ j*it+i] = x [ i ] + y [j*it+(i-1)];
}
}
I am using this assembly code in a .asm file as a function for the nested for:
.global for_asm
.sect ".text:appFastCode"
;extern void for_asm(int *ptrInput, int *ptrh,int *ptrOutput, int NN, int MM, int RR, int itera);
.map x/A4, h/B4,y/A6, N/B6, M/A8, R/B8, it/A10, it2/B10
.map xaux/A2, haux/B2, yaux/A1, yn_1/B1, i/B0,j/A0, xi/A31
.asmfunc
for_asm:
MV .S2 it,i
|| MV .S1 it2,j
|| MV x,xi ;t1 = *x
MVC .S2 i,ILC ;Inner loop count
NOP 3
[j] SPLOOP 2
|| MVC .S2 j,RILC ;Reload inner loop count
;|| SUB .D1 j,1,j ;Outer loop count
|| ZERO .L2 yn_1
;*------------Start of loop-------------------------
LDH .D1T1 *x++,xaux ;t1 = *x
|| LDH .D2T2 *h++,haux ;t2 = *h
NOP 4
ADD .L1 xaux,yn_1,yaux ;p = t1+t2 y=x[i]+h[i]
NOP 1
SPKERNEL 0
|| STH .D1 yaux,*y++ ;ADD .L1 A2,A7,A7 ;sum += p
|| MV .D2 yaux, yn_1
outer:
;*--------start epilog
;NOP
MVK .L2 0,yn_1
SPMASKR
;*--------start reload, I=0
[j] BNOP outer,4
|| [j] SUB j,1,j ;j -= 1
|| MV xi,x
NOP
;*--------branch, stop fetching
for_asm_end:
B B3
NOP 5
.endasmfunc
In the main I create an array x = [ 0,1,2,3,4...15] and it is passed as a parameter to this function with it =16, it2=2. When I see the output, it is y=[0,1,3,6,10,15,21,7,8,9,0,0,0...]. The error is always presented in the middle of the array.
I don't understand two things:
Why the output lenght is different from the expected lenght (it*it2)
Why the output is not filled with the correct data from 0 to the last field ( y [0...15] )
I can't find what is wrong and if you can help me, I would be thankful.