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

	R1: M[0] -> BIU1.T0;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU1: Load(T0)(A++) -> M[20];       //K
	BIU1: Load(T0)(A++) -> M[1];     // input freOffEstValue
	BIU1: Load(T0)(A++) -> M[2];     // Index T6
	BIU1: Load(T0)(A++) -> M[3];     // Theta
	BIU1: Load(T0)(A++) -> M[4];     //  INdex T7
	BIU1: Load(T0)(A++) -> M[5];     // PI
	BIU1: Load(T0)(A++) -> M[6];    // Output


	MFetch: REPEAT @(5);
	R5: PreConfig(M[20]);
	R5: WriteConf(Mfetch) -> KI[0-15](Mode0);
	MFetch: REPEAT @(10);
	R4: M[1] -> BIU0.T0(Mode0);
	R5: M[2] -> SHU1.T6(Mode0);
	R0: M[3] -> SHU0.T1(Mode0);
	R1: M[4] -> SHU0.T7(Mode0);
	R2: M[6] -> BIU2.T1(Mode0);
	R5: M[20] -> IMA0.T4(Mode0);

	IMA1: V(0) -> IMA1.T0 || IMA2: V(0) -> IMA2.T0;
	IMA3: V(0) -> IMA3.T0;                     // y0
	IMA1: VHigh(T0,0x8000) -> IMA1.T3 || IMA2: VHigh(T0,0x4000) -> IMA1.T1;
	IMA3: VHigh(T0,0xc000) -> IMA1.T2;

	IMA3: V(1024) -> IMA3.T1;NOP;              // x0
	IMA3: VHigh(T1,0) -> IMA3.T1;NOP;


	BIU0: Load(T0) -> IMA1.T0;
	MFetch: REPEAT @(10);
	IMA1: T0 -> IMA0.T3;NOP;


	MFetch: Lpto %ENDCORDIC @(KI1);
		IMA0: T3 + T4(W)(U)(T) -> IMA1.T0;NOP;NOP;
	//	IMA1: T0 + T0(W)(U)(T) -> IMA1.T0;NOP;

		IMA1: T0 -> IMA0.T3; NOP;
		IMA1: T0 + T3(W)(U)(T) -> IMA1.T4;NOP;
		IMA1: T0 - T3(W)(U)(T) -> IMA1.T5;NOP;
		IMA1: CompSel(T0,T1,T5,T0)(W) -> IMA1.T0;NOP;
		IMA1: CompSel(T0,T2,T0,T4)(W) -> IMA1.T0;NOP;
		IMA1: T0 -> IMA0.T1;
		SHU1: VImm(0) -> SHU1.T0;

		Mfetch: Lpto %END_ITERATIONS_16 @(KI2);
			IMA0: T1 >> 8(W) -> IMA0.T2;NOP;
			IMA0: T2 -> M[19];
			R5: PreConfig(M[19][0]);
 			R5: WriteConf(Mfetch) -> KI[3](Mode0);
 			SHU1: T0 | T0 -> IMA3.T4 || SHU0: Index(T1,T7)(T7 = T7 + V(4)) -> IMA0.T0;
 			MFetch: REPEAT @(6);
			IMA3: T1 >> T4(W) -> IMA3.T2;
			IMA3: T0 >> T4(W) -> IMA3.T3;

			MFetch: IF(KI3<KI11) JUMP %IFELSE_0;

 				IMA3: 0 - T2(W) -> IMA3.T2;
 				IMA0: 0 - T0(W) -> IMA0.T0;
 				IMA3: 0 - T3(W) -> IMA3.T3;
 				NOP;NOP;

 			IFELSE_0:
				IMA0: T1 - T0(W) -> IMA0.T1;
				IMA3: T0 + T2(W) -> IMA3.T0 || SHU1: T0 + V(1) -> SHU1.T0;
				IMA3: T1 - T3(W) -> IMA3.T1;
				NOP;NOP;


		END_ITERATIONS_16:
			IMA0: T3 -> BIU0.T2;
			IMA3: CPRS(T0)(CprsMode1) -> IMA2.T0;
			IMA3: CPRS(T1)(CprsMode1) -> IMA2.T1;
			IMA2: T0 << 16(W)(U) -> IMA2.T0 || IMA3: V(0) -> IMA3.T0;
			BIU0: Store(T2,T0);
			IMA2: T0 + T1(W) -> BIU2.T0 || IMA3: V(1024) -> IMA3.T1;
			NOP;NOP;
			IMA3: VHigh(T1,0) -> IMA3.T1;
			BIU2: Store(T0,T1)(A++);




	ENDCORDIC:

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










