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

	.global SlidingCorrelationSecondAsm
	SlidingCorrelationSecondAsm:
	R1:M[0]->BIU1.T0;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU1:Load(T0)(A++) -> M[0](Mode0);
	BIU1:Load(T0)(A++) -> M[1](Mode0);//InputA
	BIU1:Load(T0)(A++) -> M[2](Mode0);//InputB
	BIU1:Load(T0)(A++) -> M[3](Mode0);//InputA2
	BIU1:Load(T0)(A++) -> M[4](Mode0);//InputB2
	//BIU1:Load(T0)(A++) -> M[5](Mode0);//useless
	BIU1:Load(T0)(A++) -> M[6](Mode0);//Maxdata
  BIU1:Load(T0)(A++) -> M[63](Mode0);//KI0
	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);
	R3:M[0] -> IMA3.T0(Mode0);
	R5:PreConfig(M[63])(Mode0);
	R5:WriteConf(Mfetch)->KI[0-3](Mode0)||IMA0:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	R5:WriteConf(Mfetch)->KI[4-7](Mode0)||IMA1:SetShiftMode(T0) -> SHIFTMODE0(Mode0);
	IMA2:SetShiftMode(T0) -> SHIFTMODE0(Mode0)||R2:M[6]->BIU2.T0(Mode0);
	IMA0:0+0*0(ShiftMode0)(C)(B)(SSS)(T) -> IMA0.MR(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
MFetch:LPTO %Sum_1024 @(KI0 - 0);
	BIU0:Load(T0)(A++) -> IMA0.T1(Mode0)||BIU3:Load(T0)(A++) -> IMA0.T2(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	IMA0: MR+T1*T2(ShiftMode0)(C)(S)(SSS)(T) -> IMA0.MR(Mode0);
	NOP;
	NOP;
	NOP;
	//IMA0:SetMR(0)(H)(Mode0);
Sum_1024:
	//IMA0: MR + 0*0(ShiftMode0)(C)(S)(SSS)(T) -> IMA0.T3(Mode0);
	R0:M[3] -> BIU0.T0(Mode0);
	R3:M[4] -> BIU3.T0(Mode0);
	IMA0:ReadMR(L)->IMA2.T0;//real
	IMA0:ReadMR(O1)->IMA2.T2;//overflow real
	NOP;
	NOP;
	NOP;
	NOP;
	IMA2:T0>>10(W)(U)->T0;
	NOP;
	NOP;
	IMA2:T2>>16(W)(U)->T2;
	IMA2:Ttmp<<22(W)(T)->IMA2.T2;
	IMA2:T0+Ttmp(W)(U)->IMA1.T3;
	IMA3:V(1) -> IMA3.T1;
	IMA3:V(0) -> IMA3.T0;
	IMA1:V(0) -> IMA1.T0;

MFetch:LPTO %Slide_Win @(KI2 - 0);
	BIU0:Load(T0)(A++) -> IMA0.T0(Mode0)||BIU3:Load(T0)(A++) -> IMA0.T1(Mode0);
	BIU0:Load(T0)(A++) -> IMA0.T2(Mode0)||BIU3:Load(T0)(A++) -> IMA0.T3(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	IMA0:MR-T0*T1(ShiftMode0)(C)(S)(SSS)(T) -> IMA0.MR(Mode0)||IMA3:T0 + T1(S)(T) -> IMA3.T0;
	NOP;
	NOP;
	NOP;
	IMA0:MR+T2*T3(ShiftMode0)(C)(S)(SSS)(T) -> IMA0.MR(Mode0);
	NOP;
	NOP;
	NOP;
	IMA0:SetMR(0)(H);
	NOP;
	IMA0:ReadMR(L)-> IMA2.T0(Mode0)||IMA3:T0-> IMA1.T1;
	IMA0:ReadMR(O1)-> IMA2.T2(Mode0);
	NOP;
	NOP;
	NOP;
	NOP;
	IMA2:T0>>10(W)(U)->T0;
	NOP;
	NOP;
	IMA2:T2>>16(W)(U)->T2;
	IMA2:Ttmp<<22(W)(T)->IMA2.T2;
	IMA2:T0+Ttmp(W)(U)->IMA1.T2;
	NOP;
	NOP;
	IMA1:CompSel(T2, T3 , T2, T3) (W) -> IMA1.T3(Mode0);
	IMA1:CompSel(T2, T3 , T1, T0) (W) -> IMA1.T0(Mode0);
Slide_Win:
	NOP;
	NOP;
	NOP;
	NOP;
	IMA1:T0 -> BIU2.T1;
	IMA1:T3 -> BIU2.T2;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU2:Store(T1,T0)(Mode0)(A++);
	BIU2:Store(T2,T0)(Mode0)(A++);
	//BIU2:Store(T3,T0)(Mode0)(A++);
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	NOP;
	MFetch:REPEAT @(10);
	MFetch:MPU.STOP;
