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

	R1: M[0] -> BIU1.T0;
	NOP;
	NOP;
	NOP;
	NOP;
	BIU1: Load(T0)(A++) -> M[20] || IMA0: V(512) -> IMA0.T0(Mode0);
	BIU1: Load(T0)(A++) -> M[1];                                           // sym1
	BIU1: Load(T0)(A++) -> M[2];                                           // sym2
	BIU1: Load(T0)(A++) -> M[3] || IMA0: VHigh(T0,0) -> IMA0.T0(Mode0);    // Index T6
	BIU1: Load(T0)(A++) -> M[4];                                           // Theta
	BIU1: Load(T0)(A++) -> M[5] || IMA0: SetShiftMode(T0)-> ShiftMode0(Mode0); //OUT
	BIU1: Load(T0)(A++) -> M[6];
	BIU1: Load(T0)(A++) -> M[7];                                              //INDEX7
	NOP;
	R5: PreConfig(M[20]);
	R5: WriteConf(Mfetch) -> KI[0-15](Mode0);
	R4: M[1] -> BIU0.T0(Mode0);
	R5: M[2] -> BIU1.T1(Mode0);
	R0: M[3] -> SHU0.T6(Mode0);
	R0: M[3] -> SHU1.T6(Mode0);
	R4: M[4] -> SHU0.T1(Mode0);
	R2: M[5] -> BIU2.T1(Mode0);
	R0: M[7] -> SHU0.T7(Mode0);
	IMA0: SetMR(0)(L);
	IMA0: SetMR(0)(H);
	NOP;
	NOP;
	Mfetch: Lpto %MFA @(KI0);
	BIU0: Wait 0 || BIU1: Wait 0 || IMA0: Wait 11 ;
	BIU0: Load(T0)(A++) -> IMA0.T0(Mode0) || IMA0: MR + T1*T0(ShiftMode0)(C)(S)(SSS) -> IMA0.MR(Mode0);
	BIU1: Load(T1)(A++) -> IMA0.T1(Mode0);

	MFA:
	BIU0: Wait 0 || BIU1: Wait 0 || IMA0: Wait 0 ;
	MFetch: REPEAT @(15);

	IMA0: ReadMR(L) -> IMA0.T0;   // real
	IMA0: ReadMR(H) -> IMA1.T0;   // imag
	NOP;NOP;NOP;NOP;
	IMA0: T0 >> 12(W) -> IMA0.T0 || IMA1: T0 >> 12(W) -> IMA1.T0;
	NOP;NOP;

	IMA0: RAdd(T0)(W)(SlipMode1) -> SHU0.T2;
	IMA1: RAdd(T0)(W)(SlipMode1) -> SHU1.T2;
	SHU1: VImm(0) -> SHU1.T0;
	IMA0: V(0) -> IMA0.T1;
	NOP;

	SHU0: Index(T2,T6) -> IMA3.T1;
	SHU1: Index(T2,T6) -> IMA3.T0;
	NOP;NOP;

	IMA3: RAdd(T0)(W)(SlipMode1) -> IMA3.T0;
	IMA3: RAdd(T1)(W)(SlipMode1) -> IMA3.T1;

	MFetch: REPEAT @(5);
	IMA3: T0 -> IMA2.T0;
	IMA3: T1 -> IMA2.T1;
	MFetch: REPEAT @(5);

	//CORDIC ATAN2


 	Mfetch: Lpto %ENDCORDIC @(KI1);
 	IMA3: T0 -> M[19];
 	NOP;
 	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;
 	NOP;NOP;NOP;NOP;
	IMA3: T1 >> T4(W) -> IMA3.T2;
	IMA3: T0 >> T4(W) -> IMA3.T3;
	NOP;

 	MFetch: IF(KI3>=KI11) JUMP %IFFI;

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

 	IFFI:
		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;


ENDCORDIC:
	MFetch: REPEAT @(10);
	IMA0: T1 -> BIU2.T0(Mode0);
	NOP;NOP;NOP;NOP;
	BIU2: Store(T0,T1)(A++);





	MFetch:MPU.STOP;


