.section .text.m0, "ax"
	.file	"SyncVer.m0.asm"
	// DO NOT MODIFY THE CONTENT ABOVE

	.global SyncVerAsm
	SyncVerAsm:


	R1:M[0]->BIU1.T0;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU1:Load(T0)(A++) -> M[0](Mode0);//ShiftMode
	BIU1:Load(T0)(A++) -> M[1](Mode0);//InputA
	BIU1:Load(T0)(A++) -> M[2](Mode0);//InputB
	BIU1:Load(T0)(A++) -> M[3](Mode0);//Output store result
	BIU1:Load(T0)(A++) -> M[4](Mode0);//Output1 sum the first 1024 vector
	BIU1:Load(T0)(A++) -> M[5](Mode0);//Output2 slide window
	BIU1:Load(T0)(A++) -> M[6](Mode0);//Maxdata
    BIU1:Load(T0)(A++) -> M[63](Mode0);//KI0
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	R0:M[0] -> IMA0.T0(Mode0);
	R0:M[1] -> BIU0.T0(Mode0) || R1:M[0] -> IMA1.T0(Mode0);
	R3:M[2] -> BIU3.T0(Mode0) || R2:M[0] -> IMA2.T0(Mode0);
	R2:M[3] -> BIU2.T0(Mode0) || R3:M[0] -> IMA3.T0(Mode0);

	R5:PreConfig(M[63])(Mode0);
	R5:WriteConf(Mfetch)->KI[0-3](Mode0);
	R5:WriteConf(Mfetch)->KI[4-7](Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	IMA0:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	IMA1:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	IMA2:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	IMA3:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
MFetch:LPTO %SlidingCorrelation @(KI0 - 0);
	BIU0:Load(T0)(A++) -> IMA0.T1(Mode0)||BIU3:Load(T0)(A++) -> IMA0.T2(Mode0);  // load vector A and vector B
	BIU0:Load(T0)(A++) -> IMA1.T1(Mode0)||BIU3:Load(T0)(A++) -> IMA1.T2(Mode0);  // load vector A and vector B
	BIU0:Load(T0)(A++) -> IMA2.T1(Mode0)||BIU3:Load(T0)(A++) -> IMA2.T2(Mode0);  // load vector A and vector B
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	// 进行复数乘法
	IMA0: 0+T1*T2(ShiftMode0)(C)(S)(SSS)(T) -> BIU2.T1(Mode0);
	IMA1: 0+T1*T2(ShiftMode0)(C)(S)(SSS)(T) -> BIU2.T2(Mode0);
	IMA2: 0+T1*T2(ShiftMode0)(C)(S)(SSS)(T) -> BIU2.T3(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU2:Store(T1,T0)(Mode0)(A++);
	BIU2:Store(T2,T0)(Mode0)(A++);
	BIU2:Store(T3,T0)(Mode0)(A++);
SlidingCorrelation:
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	R1:M[4] -> BIU1.T0(Mode0)||SHU0:VImm(1) -> SHU0.T0(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU1:Load(T0)(A++) -> IMA0.T3(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	IMA0:VHigh(T3,0)->IMA0.T3;
	NOP;
	NOP;
	IMA0:T3 >> 1(S)->IMA0.T3;
	NOP;
	NOP;
MFetch:LPTO %Sum_1024 @(KI1 - 1);
	BIU1:Load(T0)(A++) -> IMA0.T1(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	IMA0:VHigh(T1,0)->IMA0.T1;
	NOP;
	NOP;
	/*IMA0:T1 >> 1(S)->IMA0.T1;*/
	NOP;
	NOP;
	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;
	NOP;
	NOP;
	NOP;
	BIU3:Store(T1,T0)(Mode0)(A++);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU3:Store(T2,T0)(Mode0)(A++);

	MFetch:REPEAT @(10);
	MFetch:MPU.STOP;

