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

	.global AddCPAsm


AddCPAsm:
        R1:M[0]->BIU1.T0;
	    NOP;
	    NOP;
	    NOP;
		BIU1:Load(T0)(A++) -> M[0](Mode0);	//ConfigMFetch
		BIU1:Load(T0)(A++) -> M[1](Mode0);	//BIU0.T0_input
		BIU1:Load(T0)(A++) -> M[2](Mode0);	//BIU1.T0_input
		BIU1:Load(T0)(A++) -> M[3](Mode0);	//BIU2.T1_output dm0 symbol1
		BIU1:Load(T0)(A++) -> M[4](Mode0);	//BIU2.T2_output dm0
		BIU1:Load(T0)(A++) -> M[5](Mode0);	//BIU3.T1_output dm1 symbol1
		BIU1:Load(T0)(A++) -> M[6](Mode0);	//BIU3.T2_output dm1
		BIU1:Load(T0)(A++) -> M[7](Mode0);	//BIU0.T1 input cp1
		BIU1:Load(T0)(A++) -> M[8](Mode0);	//BIU0.T2 input cp2-4
		BIU1:Load(T0)(A++) -> M[9](Mode0);	//BIU1.T1 input cp1
		BIU1:Load(T0)(A++) -> M[10](Mode0);	//BIU1.T2 input cp2-4
		BIU1:Load(T0)(A++) -> M[11](Mode0);	//BIU2.T1 output cp1
		BIU1:Load(T0)(A++) -> M[12](Mode0);	//BIU2.T2 output cp2-4
		BIU1:Load(T0)(A++) -> M[13](Mode0);	//BIU3.T1 output cp1
		BIU1:Load(T0)(A++) -> M[14](Mode0);	//BIU3.T2 output cp2-4
		BIU1:Load(T0)(A++) -> M[15](Mode0);	//BIU0.T3 input phase factor
		BIU1:Load(T0)(A++) -> M[16](Mode0);	//index1
		BIU1:Load(T0)(A++) -> M[17](Mode0);	//index2
		BIU1:Load(T0)(A++) -> M[20](Mode0);
        R5:PreConfig(M[0])(Mode0);
		R5:WriteConf(Mfetch)->KI[0-3](Mode0);
        R5:PreConfig(M[0])(Mode0);
		R5:WriteConf(Mfetch)->KI[4-7](Mode0);
		R0:M[1] -> BIU0.T0(Mode0)||R1:M[2] -> BIU1.T0(Mode0);
		R2:M[3] -> BIU2.T1(Mode0)||R3:M[5] -> BIU3.T1(Mode0);
		R2:M[4] -> BIU2.T2(Mode0)||R3:M[6] -> BIU3.T2(Mode0);
		R0:M[7] -> BIU0.T1(Mode0)||R1:M[9] -> BIU1.T1(Mode0);
		R0:M[8] -> BIU0.T2(Mode0)||R1:M[10] -> BIU1.T2(Mode0);
		R1:M[20] -> IMA1.T0(Mode0)|| 	R2:M[20] -> IMA2.T0(Mode0);
		R0:M[15] -> BIU0.T3(Mode0);
		R1:M[16] -> SHU1.T6(Mode0)|| 	R2:M[16] -> SHU2.T6(Mode0);
		R1:M[17] -> SHU1.T7(Mode0)|| 	R2:M[17] -> SHU2.T7(Mode0)|| 	IMA1: SetShiftMode (T0) -> SHIFTMODE0 (Mode0)|| 	IMA2: SetShiftMode (T0) -> SHIFTMODE0 (Mode0);
	    NOP;
		BIU0:Load(T3)(A++) -> SHU1.T0(Mode0);
		BIU0:Load(T3)(A++) -> SHU2.T0(Mode0);

		MFetch:REPEAT @(9);


		BIU0:Wait 0  || BIU1:Wait 0  || IMA1: Wait 10  || IMA2: Wait 10  || BIU2:Wait 15  || BIU3:Wait 15 ;

		SHU1:Index(T0,T7)(T7=T7+T6) -> IMA1.T2 (Mode0)|| 	SHU2:Index(T0,T7)(T7=T7+T6) -> IMA2.T2 (Mode0);
		MFetch:LPTO %AddCPAsmCyc0 @(KI1 - 0);	//dm0/dm1 symbol1
		BIU0:Load(T0)(A++) -> IMA1.T0(Mode0) ||	IMA1:  0 + T0*T2(ShiftMode0)(C)(S)(SSS)(P) -> BIU2.T0 (Mode0) || BIU2:Store(T0,T1)(A++)(Mode0) || BIU1:Load(T0)(A++) -> IMA2.T0(Mode0) || IMA2: 0 + T0*T2(ShiftMode0)(C)(S)(SSS)(P) -> BIU3.T0 (Mode0) || BIU3:Store(T0,T1)(A++)(Mode0);
		AddCPAsmCyc0:
		MFetch:REPEAT @(28);

MFetch:IF(KI0 ==KI7) JUMP %AddCPAsm4ant;

		MFetch:LPTO %AddCPAsmCyc1 @(KI0 - 0);	//symbol2-4
		SHU1:Index(T0,T7)(T7=T7+T6) -> IMA1.T2 (Mode0)|| 	SHU2:Index(T0,T7)(T7=T7+T6) -> IMA2.T2 (Mode0);
		MFetch:LPTO %AddCPAsmCyc2 @(KI1 - 0);
		BIU0:Load(T0)(A++) -> IMA1.T0(Mode0)|| 	IMA1: 0 + T0*T2(ShiftMode0)(C)(S)(SSS)(P) -> BIU2.T0 (Mode0)|| 	BIU2:Store(T0,T2)(A++)(Mode0)|| 	BIU1:Load(T0)(A++) -> IMA2.T0(Mode0)|| 	IMA2: 0 + T0*T2(ShiftMode0)(C)(S)(SSS)(P) -> BIU3.T0 (Mode0)|| 	BIU3:Store(T0,T2)(A++)(Mode0);
		AddCPAsmCyc2:
		MFetch:REPEAT @(17);
		AddCPAsmCyc1:
AddCPAsm4ant:
        BIU0:Wait 0  || 	BIU1:Wait 0  || 	BIU2:Wait 0  || 	BIU3:Wait 0  || 	IMA0: Wait 0 || 	IMA1: Wait 0 || 	IMA2: Wait 0 || 	IMA3: Wait 0 || 	R0:Wait 0  || 	R1:Wait 0  || 	R2:Wait 0  || 	R3:Wait 0  || 	SHU0:Wait 0   || 	SHU1:Wait 0   || 	SHU2:Wait 0   || 	SHU3:Wait 0  ;
		MFetch:REPEAT @(17);

	//add cp

		R2:M[11] -> BIU2.T1(Mode0) ||  R3:M[13] -> BIU3.T1(Mode0);
		R2:M[12] -> BIU2.T2(Mode0) ||  R3:M[14] -> BIU3.T2(Mode0);
		BIU0:Wait 0   || 	BIU1:Wait 0   || 	R2:Wait 9  || 	R3:Wait 9  || 	BIU2:Wait 13  || 	BIU3:Wait 13   ;
	//cp1
		MFetch:LPTO %AddCPAsmCyc3 @(KI2 - 0);	//dm0 symbol1
		BIU0:Load(T1)(A++) -> M[1](Mode0)|| 	R2:M[1] -> BIU2.T0(Mode0)|| 	BIU2:Store(T0,T1)(A++)(Mode0);
		BIU0:Load(T1)(A++) -> M[1](Mode0)|| 	R2:M[1] -> BIU2.T0(Mode0)|| 	BIU2:Store(T0,T1)(A++)(Mode0);
	    NOP;
	    NOP;
	    NOP;
	    NOP;
	    NOP;
		NOP;
		AddCPAsmCyc3:

	    MFetch:LPTO %AddCPAsmCyc4 @(KI4 - 0);	//dm1 symbol1
		BIU1:Load(T1)(A++) -> M[1](Mode0)|| 	R3:M[1] -> BIU3.T0(Mode0)|| 	BIU3:Store(T0,T1)(A++)(Mode0);
		BIU1:Load(T1)(A++) -> M[1](Mode0)|| 	R3:M[1] -> BIU3.T0(Mode0)|| 	BIU3:Store(T0,T1)(A++)(Mode0);
     	NOP;
    	NOP;
    	NOP;
	    NOP;
    	NOP;
		NOP;
		AddCPAsmCyc4:
MFetch:IF(KI0 ==KI7) JUMP %AddCPAsm5ant;
	//cp2-4
		MFetch:LPTO %AddCPAsmCyc5 @(KI0 - 0);	//dm0 and dm1 symbol 2-4
		MFetch:LPTO %AddCPAsmCyc6 @(KI3 - 0);
		BIU0:Load(T2)(A++) -> M[1](Mode0)|| 	R2:M[1] -> BIU2.T0(Mode0)|| 	BIU2:Store(T0,T2)(A++)(Mode0)|| 	BIU1:Load(T2)(A++) -> M[32](Mode0)|| 	R3:M[32] -> BIU3.T0(Mode0)|| 	BIU3:Store(T0,T2)(A++)(Mode0);
		BIU0:Load(T2)(A++) -> M[1](Mode0)|| 	R2:M[1] -> BIU2.T0(Mode0)|| 	BIU2:Store(T0,T2)(A++)(Mode0)|| 	BIU1:Load(T2)(A++) -> M[32](Mode0)|| 	R3:M[32] -> BIU3.T0(Mode0)|| 	BIU3:Store(T0,T2)(A++)(Mode0);
	    NOP;
    	NOP;
    	NOP;
        NOP;
    	NOP;
		NOP;
		AddCPAsmCyc6:
		AddCPAsmCyc5:
AddCPAsm5ant:
		BIU0:Wait 0  || 	BIU1:Wait 0  || 	BIU2:Wait 0  || 	BIU3:Wait 0  || 	IMA0: Wait 0 || 	IMA1: Wait 0 || 	IMA2: Wait 0 || 	IMA3: Wait 0 || 	R0:Wait 0  || 	R1:Wait 0  || 	R2:Wait 0  || 	R3:Wait 0  || 	SHU0:Wait 0   || 	SHU1:Wait 0   || 	SHU2:Wait 0   || 	SHU3:Wait 0  ;
		MFetch:REPEAT @(25);

		MFetch:MPU.STOP;
