自己写的代码,还请大家指教!
#include <stdio.h>
extern int asmfunc(int *a,int *b); //调用时要调用数组的地址
extern int a[2] = {1,2};
extern int b[2] = {1,2};
void main()
{
int result;
result = asmfunc(a,b);
printf("sum is %d/n",result);
}
.global _asmfunc
_asmfunc:
;mvk .S 1,a2
;mvk .S 0,a1
;STW .D a2,*+b14(_a)
;LDW .D *b14(_a+4),a1
;LDW .D *+b14(_a+4),a2
mvk .L 2,A1
ZERO .L A7
|| ZERO .L B7
LOOP: LDW .D *A4++,A2 //访问数组 W是以字为单位
NOP 4
MVK .S 12,A0
STW .D A0,*A4 //给数组赋值
|| LDW .D *B4++,B2
|| SUB .S A1,1,A1
NOP 4
[A1] B .S LOOP
NOP 2
add .L B2,A2,A3 //跳转指令延迟5周期,这样提高并行
MV .L A3,A4
B .S2 b3
NOP 5
.end