	.section .text.m0, "ax"
	.file	"RMBitSelLDPCAsm.m0.asm"
	// DO NOT MODIFY THE CONTENT ABOVE
.global RMBitSelLDPCAsm
RMBitSelLDPCAsm:
	R1: M[0] -> BIU1.T0;
		NOP;
		NOP;
		NOP;
		BIU1:Load(T0)(A++) -> M[63];
		BIU1:Load(T0)(A++) -> M[62];
		BIU1:Load(T0)(A++) -> M[61];
		BIU1:Load(T0)(A++) -> M[60];
		BIU1:Load(T0)(A++) -> M[59];
		BIU1:Load(T0)(A++) -> M[58];
		BIU1:Load(T0)(A++) -> M[57];
		BIU1:Load(T0)(A++) -> M[56];
		BIU1:Load(T0)(A++) -> M[55];
		BIU1:Load(T0)(A++) -> M[54]|| 	R5:PreConfig(M[63]);
		BIU1:Load(T0)(A++) -> M[53]|| 	R0:M[62] -> BIU0.T1 || R5:WriteConf(Mfetch)->KI[0-15];
		BIU1:Load(T0)(A++) -> M[52]|| 	R2:M[61] -> BIU2.T1;
		BIU1:Load(T0)(A++) -> M[51]|| 	R0:M[60] -> BIU0.T2;
		R2:M[59] -> BIU2.T2;
		R0:M[58] -> BIU0.T3;
		R2:M[57] -> BIU2.T3;
		NOP;
		NOP;

		BIU0:Wait 0   || 	SHU1:Wait 10   || 	BIU2:Wait 13   ;
		MFetch:IF(KI8 == 0) JUMP %RMLDPCAsmShorten ;
		//RMLDPCAsmRepeat

//bit to byte
		BIU0:Load(T1)(A++) -> SHU1.T0|| 	SHU1:InsertBit(T0,1)(U) -> BIU2.T0|| 	BIU2:Store(T0,T1)(A++)|| 	MFetch:REPEAT @(KI0 - 0);
		MFetch:REPEAT @(17);
//remove null bit
		BIU0:Load(T2)(A++) -> SHU1.T0|| 	SHU1:T0 + V(0) -> BIU2.T0|| 	BIU2:Store(T0,T2)(A++)|| 	MFetch:REPEAT @(KI1 - 0);
		MFetch:IF(KI2 == 0) JUMP %RMLDPCAsmRepeatk0;
		BIU0:Load(T3)(A++) -> SHU1.T0|| 	SHU1:T0 + V(0) -> BIU2.T0|| 	BIU2:Store(T0,T3)(A++)|| 	MFetch:REPEAT @(KI2 - 0);
RMLDPCAsmRepeatk0:

		MFetch:REPEAT @(21);
		R0:M[56] -> BIU0.T1;
		R2:M[55] -> BIU2.T1;
		R0:M[54] -> BIU0.T2;
		R2:M[53] -> BIU2.T2;
		R0:M[52] -> BIU0.T3;
		R2:M[51] -> BIU2.T3;
		BIU0:Load(T1)(A++) -> SHU1.T0|| 	SHU1:T0 + V(0) -> BIU2.T0|| 	BIU2:Store(T0,T1)(A++)|| 	MFetch:REPEAT @(KI3 - 0);
		MFetch:IF(KI4 == 0) JUMP %RMLDPCAsmRepeatSeg3 ;
		MFetch:LPTO %RMLDPCAsmRepeatSeg3 @(KI4 - 0);
		BIU0:Load(T2)(A++) -> SHU1.T0|| 	SHU1:T0 + V(0) -> BIU2.T0|| 	BIU2:Store(T0,T2)(A++)|| 	MFetch:REPEAT @(KI5 - 0);
RMLDPCAsmRepeatSeg3:
		MFetch:IF(KI6 == 0) JUMP %RMLDPCAsmENDBITSELECT ;
		BIU0:Load(T3)(A++) -> SHU1.T0|| 	SHU1:T0 + V(0) -> BIU2.T0|| 	BIU2:Store(T0,T3)(A++)|| 	MFetch:REPEAT @(KI6 - 0);
MFetch:JUMP %RMLDPCAsmENDBITSELECT;


RMLDPCAsmShorten:
		BIU0:Load(T1)(A++) -> SHU1.T0|| 	SHU1:InsertBit(T0,1)(U) -> BIU2.T0|| 	BIU2:Store(T0,T1)(A++)|| 	MFetch:REPEAT @(KI0 - 0);
MFetch:IF(KI1 == 0) JUMP %RMLDPCAsmShortenRemoveNullbit;
		BIU0:Load(T2)(A++) -> SHU1.T0|| 	SHU1:InsertBit(T0,1)(U) -> BIU2.T0|| 	BIU2:Store(T0,T2)(A++)|| 	MFetch:REPEAT @(KI1 - 0);
RMLDPCAsmShortenRemoveNullbit:
		MFetch:REPEAT @(8);
		R0:M[58] -> BIU0.T1 || R2:M[57] -> BIU2.T1;
		R0:M[56] -> BIU0.T2 || R2:M[55] -> BIU2.T2;
		NOP;
		NOP;
		NOP;
		BIU0:Load(T1)(A++) -> SHU1.T0 || SHU1:T0 + V(0) -> BIU2.T0 || BIU2:Store(T0,T1)(A++)|| 	MFetch:REPEAT @(KI2 - 0);
		MFetch:IF(KI3 == 0) JUMP %RMLDPCAsmENDBITSELECT;
		BIU0:Load(T2)(A++) -> SHU1.T0 || SHU1:T0 + V(0) -> BIU2.T0 || BIU2:Store(T0,T2)(A++)|| 	MFetch:REPEAT @(KI3 - 0);


MFetch:JUMP %RMLDPCAsmENDBITSELECT;


RMLDPCAsmENDBITSELECT:
		BIU0:Wait 0   || 	SHU1:Wait 0   || 	BIU2:Wait 0   ;
		MFetch:REPEAT @(16);
		MFetch:MPU.STOP;
