data/full_repos/permissive/140357212/Tomasulo/controleestacao.v
 line:111: before: "begin"
1: b"%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:88: Too many digits for 32 bit number: 11111111111111111111\n        ... As that number was unsized ('d...) it is limited to 32 bits (IEEE 1800-2017 5.7.1)\n        ... Suggest adding a size to it.\n  InputTime[LabelAddSub]=11111111111111111111;\n                         ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:111: syntax error, unexpected '@'\n  @(posedge clk) begin\n  ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:213: syntax error, unexpected '=', expecting IDENTIFIER\n      Runaddsum = 0;\n                ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:219: syntax error, unexpected wait\n        wait(updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;\n        ^~~~\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:224: syntax error, unexpected '=', expecting IDENTIFIER\n        AddSubFull = AddSubFull - 1;\n                   ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:230: syntax error, unexpected '[', expecting IDENTIFIER\n         TagI[i] = 9'b111111111;\n             ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:234: syntax error, unexpected '[', expecting IDENTIFIER\n        TagJ[i] = 9'b111111111;\n            ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:241: syntax error, unexpected '=', expecting IDENTIFIER\n      if(minInputTime == 9'b111111111) minInputTime = i;\n                                                    ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:243: syntax error, unexpected '=', expecting IDENTIFIER\n       minInputTime = i; \n                    ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:247: syntax error, unexpected '[', expecting IDENTIFIER\n     Exec[minInputTime] = 1;\n         ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:258: syntax error, unexpected '=', expecting IDENTIFIER\n    RUNMulDiv = 0;\n              ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:263: syntax error, unexpected wait\n     wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;\n     ^~~~\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:268: syntax error, unexpected '=', expecting IDENTIFIER\n     MulDivFull = MulDivFull - 1;\n                ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:273: syntax error, unexpected '[', expecting IDENTIFIER\n      TagI[i] = 9'b111111111;\n          ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:277: syntax error, unexpected '[', expecting IDENTIFIER\n      TagJ[i] = 9'b111111111;\n          ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:284: syntax error, unexpected '=', expecting IDENTIFIER\n      if(minInputTime == 9'b111111111) minInputTime = i;\n                                                    ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:285: syntax error, unexpected '=', expecting IDENTIFIER\n      else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; \n                                                                   ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:289: syntax error, unexpected '[', expecting IDENTIFIER\n     Exec[minInputTime] = 1;\n         ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:302: syntax error, unexpected '=', expecting IDENTIFIER\n    minInputTime = 9'b111111111;\n                 ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:304: syntax error, unexpected '=', expecting IDENTIFIER\n     Runaddsum = 0;\n               ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:309: syntax error, unexpected wait\n      wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;\n      ^~~~\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:314: syntax error, unexpected '=', expecting IDENTIFIER\n      AddSubFull = AddSubFull - 1;\n                 ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:319: syntax error, unexpected '[', expecting IDENTIFIER\n       TagI[i] = 9'b111111111;\n           ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:323: syntax error, unexpected '[', expecting IDENTIFIER\n       TagJ[i] = 9'b111111111;\n           ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:331: syntax error, unexpected '=', expecting IDENTIFIER\n      if(minInputTime == 9'b111111111) minInputTime = i;\n                                                    ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:332: syntax error, unexpected '=', expecting IDENTIFIER\n      else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; \n                                                                   ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:336: syntax error, unexpected '=', expecting IDENTIFIER\n     firstInst = 0;\n               ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:348: syntax error, unexpected '=', expecting IDENTIFIER\n    minInputTime = 9'b111111111;\n                 ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:350: syntax error, unexpected '=', expecting IDENTIFIER\n     RUNMulDiv = 0;\n               ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:356: syntax error, unexpected wait\n      wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;\n      ^~~~\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:361: syntax error, unexpected '=', expecting IDENTIFIER\n      MulDivFull = MulDivFull - 1;\n                 ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:366: syntax error, unexpected '[', expecting IDENTIFIER\n       TagI[j] = 9'b111111111;\n           ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:370: syntax error, unexpected '[', expecting IDENTIFIER\n       TagJ[j] = 9'b111111111;\n           ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:379: syntax error, unexpected '=', expecting IDENTIFIER\n        minInputTime = j; \n                     ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:382: syntax error, unexpected '=', expecting IDENTIFIER\n       minInputTime = j; \n                    ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:386: syntax error, unexpected '=', expecting IDENTIFIER\n     firstInstMulDiv = 0;\n                     ^\n%Error: data/full_repos/permissive/140357212/Tomasulo/controleestacao.v:398: syntax error, unexpected end\n end\n ^~~\n%Error: Exiting due to 37 error(s)\n"
module controle(clk,inst_saida,regs_s0,regs_s1,regs_s2,regs_s3,label_add_saida,Tempo,Add_full_saida,Mult_full_saida);
		input clk;

		parameter SOM = 3'b000;
		parameter SUB = 3'b001;
		parameter MUL = 3'b010;
		parameter DIV = 3'b011;

		integer i,j;	
		wire [20:0]Time;
		reg breakLoop;
		reg [20:0]minInputTime;
		reg firstInst,firstInstMulDiv;
		output reg [8:0]inst_saida;
		output reg [8:0]regs_s0,regs_s1,regs_s2,regs_s3;
		output reg [2:0]label_add_saida;
		output reg [20:0]Tempo;
		output reg [2:0] Add_full_saida;
		output reg [2:0] Mult_full_saida;
		

		wire [8:0]InInst;
		wire [3:0]InputX,InputY,InputI;
		assign InputX = InInst[8:6];
		assign InputY = InInst[5:3];
		assign InputI = InInst[2:0];
	

		reg [2:0]AddSubFull,MulDivFull;
	

		wire DoneMulDiv,DoneAddSub;

		reg Runaddsum;
		reg [2:0]AddSubOp,InputX_AddSub,InLabelAddSub;
		wire [2:0]AddressAddSubX,LabelAddSub;
		reg [8:0]RegAddSubX,RegAddSubY;
		wire [8:0]ResultAddSub;

		reg RUNMulDiv;
		reg [2:0]OpMulDiv,InMulDivX,InLabelMulDiv;
		wire [2:0]AddressMulDivX,LabelMulDiv;
		reg [8:0]RegMulDivX,RegMulDivY;
		wire [8:0]ResultMulDiv;
	
	

		wire [8:0]Tags[6:0];
		wire [8:0]Regs[6:0];
		reg updateData[6:0];
		reg updateLabel[6:0];
		reg [8:0]newData, newLabel; 
	

		reg [0:0]Busy[5:0];
		reg [8:0]ValueI[5:0];
		reg [8:0]ValueJ[5:0];
		reg [8:0]TagI[5:0];
		reg [8:0]TagJ[5:0];	
		reg [8:0]Insts[5:0];
		reg Exec[5:0];
		reg [20:0]InputTime[5:0];

		wire [3:0]I,X,Y; 
	
	initial begin
		InputTime[LabelAddSub]=11111111111111111111;
		AddSubFull = 0;
		MulDivFull = 0;
		firstInst = 1;
		Runaddsum = 0;
		RUNMulDiv = 0;
		firstInstMulDiv = 1;
		for(i = 0; i <= 6; i = i + 1) begin
			updateLabel[i] = 0;
			updateData[i] = 0;
		end
		for(i = 0; i <= 5; i = i + 1) begin
			Busy[i] = 0;
			Exec[i] = 0;
		end
	end
	
	always @(clk) begin
		breakLoop = 0;
		for(i = 0; i <= 6; i = i + 1) begin
			updateLabel[i] = 0;
			updateData[i] = 0;
		end
		@(posedge clk) begin
		
		regs_s0=Regs[0];
		regs_s1=Regs[1];
		regs_s2=Regs[2];
		regs_s3=Regs[3];
		label_add_saida=LabelAddSub;
		Tempo=Time;
		Add_full_saida=AddSubFull;
		Mult_full_saida=MulDivFull;
		inst_saida=InInst;


		if(AddSubFull != 3 && (InputI == SOM || InputI == SUB)) begin

			for(i = 0; i <= 2 && breakLoop != 1; i = i + 1) begin 
				if(Busy[i] == 0) 
					begin
							Busy[i] = 1;
							Exec[i] = 0;
							Insts[i] = InInst;
							InputTime[i] = Time;
						if(Tags[InputX] == 9'b111111111) 
							begin
								ValueI[i] = Regs[InputX];
								TagI[i] = 9'b111111111;
							end
						else 
							begin
								TagI[i] = Tags[InputX]; 
								ValueI[i] = 9'b111111111;
							end
						if(Tags[InputY] == 9'b111111111) 
							begin
								ValueJ[i] = Regs[InputY];
								TagJ[i] = 9'b111111111;
							end
						else 
							begin
								TagJ[i] = Tags[InputY]; 
								ValueJ[i] = 9'b111111111;
							end
					newLabel = i;
					updateLabel[InputX] = 1;
					AddSubFull = AddSubFull + 1;
					breakLoop = 1;
				end
			end
		end
		breakLoop = 0;

		if(MulDivFull != 3 && (InputI == MUL || InputI == DIV)) 
			begin
				for(i = 3; i <= 5 && breakLoop != 1; i = i + 1) 
					begin
						if(Busy[i] == 0) 
							begin
								Busy[i] = 1;
								Exec[i] = 0;
								Insts[i] = InInst;
								InputTime[i] = Time;
								if(Tags[InputX] == 9'b111111111) 
									begin
										ValueI[i] = Regs[InputX];
										TagI[i] = 9'b111111111;
									end
								else 
									begin
										TagI[i] = Tags[InputX]; 
										ValueI[i] = 9'b111111111;
									end
								if(Tags[InputY] == 9'b111111111) 
									begin
										ValueJ[i] = Regs[InputY];
										TagJ[i] = 9'b111111111;
									end
								else 	
									begin
										TagJ[i] = Tags[InputY]; 
										ValueJ[i] = 9'b111111111;
									end

					newLabel = i;
					updateLabel[InputX] = 1;
					MulDivFull = MulDivFull + 1;
					breakLoop = 1;
				end
			end
		end
		end
		




		if(DoneAddSub && DoneMulDiv) 
			begin
				if(InputTime[LabelAddSub] < InputTime[LabelMulDiv])
					begin
						Runaddsum = 0;
						newData = ResultAddSub;
						updateData[AddressAddSubX] = 1;
						Busy[LabelAddSub] = 0;
						if(!(AddressAddSubX == InputX) && (Tags[AddressAddSubX] == LabelAddSub))
							begin
								wait(updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;
								newLabel = 9'b111111111;
							end

							if(AddSubFull != 0 && DoneAddSub)
								AddSubFull = AddSubFull - 1;
							minInputTime = 9'b111111111;
							
							for(i = 0; i <= 5; i = i + 1) 
							begin	
								if(TagI[i] == LabelAddSub) begin
									TagI[i] = 9'b111111111;
									ValueI[i] = ResultAddSub; 
								end
							if(TagJ[i] == LabelAddSub) begin
								TagJ[i] = 9'b111111111;
								ValueJ[i] = ResultAddSub; 
							end
				end

				for(i = 0; i <= 2; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111) && (ValueJ[i] != 9'b111111111))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) 
							minInputTime = i; 
						end
				end
				if(minInputTime != 9'b111111111) begin
					Exec[minInputTime] = 1;
					AddSubOp = Insts[minInputTime][2:0];
						RegAddSubY = ValueJ[minInputTime];
						RegAddSubX = ValueI[minInputTime];
					
					InputX_AddSub = Insts[minInputTime][8:6];
					InLabelAddSub = minInputTime;
					Runaddsum = 1;
				end
			end
			else begin
				RUNMulDiv = 0;
				newData = ResultMulDiv;
				updateData[AddressMulDivX] = 1;
				Busy[LabelMulDiv] = 0;
				if(!(AddressMulDivX == InputX) && (Tags[AddressMulDivX] == LabelMulDiv))begin
					wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;
					newLabel = 9'b111111111;
				end

				if(MulDivFull != 0 && DoneMulDiv)
					MulDivFull = MulDivFull - 1;
				minInputTime = 9'b111111111;
				
				for(i = 0; i <= 5; i = i + 1) begin	
					if(TagI[i] == LabelMulDiv) begin
						TagI[i] = 9'b111111111;
						ValueI[i] = ResultMulDiv;  
					end
					if(TagJ[i] == LabelMulDiv) begin
						TagJ[i] = 9'b111111111;
						ValueJ[i] = ResultMulDiv;
					end
				end

				for(i = 2 + 1; i <= 5; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111 ) && (ValueJ[i] != 9'b111111111 ))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					Exec[minInputTime] = 1;
					OpMulDiv = Insts[minInputTime][2:0];
						RegMulDivY = ValueJ[minInputTime];
						RegMulDivX = ValueI[minInputTime];
					
					InMulDivX = Insts[minInputTime][8:6];
					InLabelMulDiv = minInputTime;
					RUNMulDiv = 1;
				end
			end
		end
		else begin
			if(DoneAddSub || (firstInst) || !Runaddsum)begin
				minInputTime = 9'b111111111;
				if(DoneAddSub) begin
					Runaddsum = 0;
					newData = ResultAddSub;
					updateData[AddressAddSubX] = 1;
					Busy[LabelAddSub] = 0;
					if(!(AddressAddSubX == InputX) && (Tags[AddressAddSubX] == LabelAddSub))begin
						wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;
						newLabel = 9'b111111111;
					end

					if(AddSubFull != 0 && DoneAddSub)
						AddSubFull = AddSubFull - 1;
					
					
					for(i = 0; i <= 5; i = i + 1) begin	
						if(TagI[i] == LabelAddSub) begin
							TagI[i] = 9'b111111111;
							ValueI[i] = ResultAddSub;  
						end
						if(TagJ[i] == LabelAddSub) begin
							TagJ[i] = 9'b111111111;
							ValueJ[i] = ResultAddSub; 
						end
					end
				end

				for(i = 0; i <= 2; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111) && (ValueJ[i] != 9'b111111111))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					firstInst = 0;
					Exec[minInputTime] = 1;
					AddSubOp = Insts[minInputTime][2:0];
						RegAddSubY = ValueJ[minInputTime];
						RegAddSubX = ValueI[minInputTime];
					
					InputX_AddSub = Insts[minInputTime][8:6];
					InLabelAddSub = minInputTime;
					Runaddsum = 1;
				end
			end
			if(DoneMulDiv || (firstInstMulDiv) || !RUNMulDiv)begin
				minInputTime = 9'b111111111;
				if(DoneMulDiv) begin
					RUNMulDiv = 0;
					
					newData = ResultMulDiv;
					updateData[AddressMulDivX] = 1;
					Busy[LabelMulDiv] = 0;
					if(!(AddressMulDivX == InputX) && (Tags[AddressMulDivX] == LabelMulDiv))begin
						wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;
						newLabel = 9'b111111111;
					end

					if(MulDivFull != 0 && DoneMulDiv)
						MulDivFull = MulDivFull - 1;
					minInputTime = 9'b111111111;
					
					for(j = 0; j <= 5; j = j + 1) begin	
						if(TagI[j] == LabelMulDiv) begin
							TagI[j] = 9'b111111111;
							ValueI[j] = ResultMulDiv;  
						end
						if(TagJ[j] == LabelMulDiv) begin
							TagJ[j] = 9'b111111111;
							ValueJ[j] = ResultMulDiv; 
						end
					end
				end
				for(j = 2 + 1; j <= 5; j = j + 1) begin
					if(Exec[j] == 0 && ((ValueI[j] != 9'b111111111 ) && (ValueJ[j] != 9'b111111111 ))) begin
						if(minInputTime == 9'b111111111)
							begin 
								minInputTime = j; 
							end
						else if(InputTime[minInputTime] > InputTime[j]) 
							minInputTime = j; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					firstInstMulDiv = 0;
					Exec[minInputTime] = 1;
					OpMulDiv = Insts[minInputTime][2:0];
						RegMulDivY = ValueJ[minInputTime];
						RegMulDivX = ValueI[minInputTime];
					
					InMulDivX = Insts[minInputTime][8:6];
					InLabelMulDiv = minInputTime;
					RUNMulDiv = 1;
				end
			end
		end
	end

	registradorD r0(clk,newData,updateData[0],newLabel,updateLabel[0],Tags[0],Regs[0]);
	registradorD r1(clk,newData,updateData[1],newLabel,updateLabel[1],Tags[1],Regs[1]);
	registradorD r2(clk,newData,updateData[2],newLabel,updateLabel[2],Tags[2],Regs[2]);
	registradorD r3(clk,newData,updateData[3],newLabel,updateLabel[3],Tags[3],Regs[3]);
	Count_tomasulo my_time(clk,Time);
	FU_add_sub FU_add(clk,Runaddsum,RegAddSubX,RegAddSubY,AddSubOp,ResultAddSub,DoneAddSub,InputX_AddSub,InLabelAddSub,AddressAddSubX,LabelAddSub);
	FU_mul_div FU_mul(clk,RUNMulDiv,RegMulDivX,RegMulDivY,OpMulDiv,ResultMulDiv,DoneMulDiv,InMulDivX,InLabelMulDiv,AddressMulDivX,LabelMulDiv);
	iQueue instrucoes(clk,0,InInst,AddSubFull,MulDivFull);
	
endmodule
module controle(clk,inst_saida,regs_s0,regs_s1,regs_s2,regs_s3,label_add_saida,Tempo,Add_full_saida,Mult_full_saida);

		input clk;

		parameter SOM = 3'b000;
		parameter SUB = 3'b001;
		parameter MUL = 3'b010;
		parameter DIV = 3'b011;

		integer i,j;	
		wire [20:0]Time;
		reg breakLoop;
		reg [20:0]minInputTime;
		reg firstInst,firstInstMulDiv;
		output reg [8:0]inst_saida;
		output reg [8:0]regs_s0,regs_s1,regs_s2,regs_s3;
		output reg [2:0]label_add_saida;
		output reg [20:0]Tempo;
		output reg [2:0] Add_full_saida;
		output reg [2:0] Mult_full_saida;
		

		wire [8:0]InInst;
		wire [3:0]InputX,InputY,InputI;
		assign InputX = InInst[8:6];
		assign InputY = InInst[5:3];
		assign InputI = InInst[2:0];
	

		reg [2:0]AddSubFull,MulDivFull;
	

		wire DoneMulDiv,DoneAddSub;

		reg Runaddsum;
		reg [2:0]AddSubOp,InputX_AddSub,InLabelAddSub;
		wire [2:0]AddressAddSubX,LabelAddSub;
		reg [8:0]RegAddSubX,RegAddSubY;
		wire [8:0]ResultAddSub;

		reg RUNMulDiv;
		reg [2:0]OpMulDiv,InMulDivX,InLabelMulDiv;
		wire [2:0]AddressMulDivX,LabelMulDiv;
		reg [8:0]RegMulDivX,RegMulDivY;
		wire [8:0]ResultMulDiv;
	
	

		wire [8:0]Tags[6:0];
		wire [8:0]Regs[6:0];
		reg updateData[6:0];
		reg updateLabel[6:0];
		reg [8:0]newData, newLabel; 
	

		reg [0:0]Busy[5:0];
		reg [8:0]ValueI[5:0];
		reg [8:0]ValueJ[5:0];
		reg [8:0]TagI[5:0];
		reg [8:0]TagJ[5:0];	
		reg [8:0]Insts[5:0];
		reg Exec[5:0];
		reg [20:0]InputTime[5:0];

		wire [3:0]I,X,Y; 
	
	initial begin
		InputTime[LabelAddSub]=11111111111111111111;
		AddSubFull = 0;
		MulDivFull = 0;
		firstInst = 1;
		Runaddsum = 0;
		RUNMulDiv = 0;
		firstInstMulDiv = 1;
		for(i = 0; i <= 6; i = i + 1) begin
			updateLabel[i] = 0;
			updateData[i] = 0;
		end
		for(i = 0; i <= 5; i = i + 1) begin
			Busy[i] = 0;
			Exec[i] = 0;
		end
	end
	
	always @(clk) begin
		breakLoop = 0;
		for(i = 0; i <= 6; i = i + 1) begin
			updateLabel[i] = 0;
			updateData[i] = 0;
		end
		@(posedge clk) begin
		
		regs_s0=Regs[0];
		regs_s1=Regs[1];
		regs_s2=Regs[2];
		regs_s3=Regs[3];
		label_add_saida=LabelAddSub;
		Tempo=Time;
		Add_full_saida=AddSubFull;
		Mult_full_saida=MulDivFull;
		inst_saida=InInst;


		if(AddSubFull != 3 && (InputI == SOM || InputI == SUB)) begin

			for(i = 0; i <= 2 && breakLoop != 1; i = i + 1) begin 
				if(Busy[i] == 0) 
					begin
							Busy[i] = 1;
							Exec[i] = 0;
							Insts[i] = InInst;
							InputTime[i] = Time;
						if(Tags[InputX] == 9'b111111111) 
							begin
								ValueI[i] = Regs[InputX];
								TagI[i] = 9'b111111111;
							end
						else 
							begin
								TagI[i] = Tags[InputX]; 
								ValueI[i] = 9'b111111111;
							end
						if(Tags[InputY] == 9'b111111111) 
							begin
								ValueJ[i] = Regs[InputY];
								TagJ[i] = 9'b111111111;
							end
						else 
							begin
								TagJ[i] = Tags[InputY]; 
								ValueJ[i] = 9'b111111111;
							end
					newLabel = i;
					updateLabel[InputX] = 1;
					AddSubFull = AddSubFull + 1;
					breakLoop = 1;
				end
			end
		end
		breakLoop = 0;

		if(MulDivFull != 3 && (InputI == MUL || InputI == DIV)) 
			begin
				for(i = 3; i <= 5 && breakLoop != 1; i = i + 1) 
					begin
						if(Busy[i] == 0) 
							begin
								Busy[i] = 1;
								Exec[i] = 0;
								Insts[i] = InInst;
								InputTime[i] = Time;
								if(Tags[InputX] == 9'b111111111) 
									begin
										ValueI[i] = Regs[InputX];
										TagI[i] = 9'b111111111;
									end
								else 
									begin
										TagI[i] = Tags[InputX]; 
										ValueI[i] = 9'b111111111;
									end
								if(Tags[InputY] == 9'b111111111) 
									begin
										ValueJ[i] = Regs[InputY];
										TagJ[i] = 9'b111111111;
									end
								else 	
									begin
										TagJ[i] = Tags[InputY]; 
										ValueJ[i] = 9'b111111111;
									end

					newLabel = i;
					updateLabel[InputX] = 1;
					MulDivFull = MulDivFull + 1;
					breakLoop = 1;
				end
			end
		end
		end
		




		if(DoneAddSub && DoneMulDiv) 
			begin
				if(InputTime[LabelAddSub] < InputTime[LabelMulDiv])
					begin
						Runaddsum = 0;
						newData = ResultAddSub;
						updateData[AddressAddSubX] = 1;
						Busy[LabelAddSub] = 0;
						if(!(AddressAddSubX == InputX) && (Tags[AddressAddSubX] == LabelAddSub))
							begin
								wait(updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;
								newLabel = 9'b111111111;
							end

							if(AddSubFull != 0 && DoneAddSub)
								AddSubFull = AddSubFull - 1;
							minInputTime = 9'b111111111;
							
							for(i = 0; i <= 5; i = i + 1) 
							begin	
								if(TagI[i] == LabelAddSub) begin
									TagI[i] = 9'b111111111;
									ValueI[i] = ResultAddSub; 
								end
							if(TagJ[i] == LabelAddSub) begin
								TagJ[i] = 9'b111111111;
								ValueJ[i] = ResultAddSub; 
							end
				end

				for(i = 0; i <= 2; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111) && (ValueJ[i] != 9'b111111111))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) 
							minInputTime = i; 
						end
				end
				if(minInputTime != 9'b111111111) begin
					Exec[minInputTime] = 1;
					AddSubOp = Insts[minInputTime][2:0];
						RegAddSubY = ValueJ[minInputTime];
						RegAddSubX = ValueI[minInputTime];
					
					InputX_AddSub = Insts[minInputTime][8:6];
					InLabelAddSub = minInputTime;
					Runaddsum = 1;
				end
			end
			else begin
				RUNMulDiv = 0;
				newData = ResultMulDiv;
				updateData[AddressMulDivX] = 1;
				Busy[LabelMulDiv] = 0;
				if(!(AddressMulDivX == InputX) && (Tags[AddressMulDivX] == LabelMulDiv))begin
					wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;
					newLabel = 9'b111111111;
				end

				if(MulDivFull != 0 && DoneMulDiv)
					MulDivFull = MulDivFull - 1;
				minInputTime = 9'b111111111;
				
				for(i = 0; i <= 5; i = i + 1) begin	
					if(TagI[i] == LabelMulDiv) begin
						TagI[i] = 9'b111111111;
						ValueI[i] = ResultMulDiv;  
					end
					if(TagJ[i] == LabelMulDiv) begin
						TagJ[i] = 9'b111111111;
						ValueJ[i] = ResultMulDiv;
					end
				end

				for(i = 2 + 1; i <= 5; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111 ) && (ValueJ[i] != 9'b111111111 ))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					Exec[minInputTime] = 1;
					OpMulDiv = Insts[minInputTime][2:0];
						RegMulDivY = ValueJ[minInputTime];
						RegMulDivX = ValueI[minInputTime];
					
					InMulDivX = Insts[minInputTime][8:6];
					InLabelMulDiv = minInputTime;
					RUNMulDiv = 1;
				end
			end
		end
		else begin
			if(DoneAddSub || (firstInst) || !Runaddsum)begin
				minInputTime = 9'b111111111;
				if(DoneAddSub) begin
					Runaddsum = 0;
					newData = ResultAddSub;
					updateData[AddressAddSubX] = 1;
					Busy[LabelAddSub] = 0;
					if(!(AddressAddSubX == InputX) && (Tags[AddressAddSubX] == LabelAddSub))begin
						wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1  updateLabel[AddressAddSubX] = 1;
						newLabel = 9'b111111111;
					end

					if(AddSubFull != 0 && DoneAddSub)
						AddSubFull = AddSubFull - 1;
					
					
					for(i = 0; i <= 5; i = i + 1) begin	
						if(TagI[i] == LabelAddSub) begin
							TagI[i] = 9'b111111111;
							ValueI[i] = ResultAddSub;  
						end
						if(TagJ[i] == LabelAddSub) begin
							TagJ[i] = 9'b111111111;
							ValueJ[i] = ResultAddSub; 
						end
					end
				end

				for(i = 0; i <= 2; i = i + 1) begin
					if(Exec[i] == 0 && ((ValueI[i] != 9'b111111111) && (ValueJ[i] != 9'b111111111))) begin
						if(minInputTime == 9'b111111111) minInputTime = i;
						else if(InputTime[minInputTime] > InputTime[i]) minInputTime = i; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					firstInst = 0;
					Exec[minInputTime] = 1;
					AddSubOp = Insts[minInputTime][2:0];
						RegAddSubY = ValueJ[minInputTime];
						RegAddSubX = ValueI[minInputTime];
					
					InputX_AddSub = Insts[minInputTime][8:6];
					InLabelAddSub = minInputTime;
					Runaddsum = 1;
				end
			end
			if(DoneMulDiv || (firstInstMulDiv) || !RUNMulDiv)begin
				minInputTime = 9'b111111111;
				if(DoneMulDiv) begin
					RUNMulDiv = 0;
					
					newData = ResultMulDiv;
					updateData[AddressMulDivX] = 1;
					Busy[LabelMulDiv] = 0;
					if(!(AddressMulDivX == InputX) && (Tags[AddressMulDivX] == LabelMulDiv))begin
						wait( updateLabel[0] || updateLabel[1]||updateLabel[2]||updateLabel[3]||updateLabel[4]|| updateLabel[5]||updateLabel[6] == 0) #1 updateLabel[AddressMulDivX] = 1;
						newLabel = 9'b111111111;
					end

					if(MulDivFull != 0 && DoneMulDiv)
						MulDivFull = MulDivFull - 1;
					minInputTime = 9'b111111111;
					
					for(j = 0; j <= 5; j = j + 1) begin	
						if(TagI[j] == LabelMulDiv) begin
							TagI[j] = 9'b111111111;
							ValueI[j] = ResultMulDiv;  
						end
						if(TagJ[j] == LabelMulDiv) begin
							TagJ[j] = 9'b111111111;
							ValueJ[j] = ResultMulDiv; 
						end
					end
				end
				for(j = 2 + 1; j <= 5; j = j + 1) begin
					if(Exec[j] == 0 && ((ValueI[j] != 9'b111111111 ) && (ValueJ[j] != 9'b111111111 ))) begin
						if(minInputTime == 9'b111111111)
							begin 
								minInputTime = j; 
							end
						else if(InputTime[minInputTime] > InputTime[j]) 
							minInputTime = j; 
					end
				end
				if(minInputTime != 9'b111111111) begin
					firstInstMulDiv = 0;
					Exec[minInputTime] = 1;
					OpMulDiv = Insts[minInputTime][2:0];
						RegMulDivY = ValueJ[minInputTime];
						RegMulDivX = ValueI[minInputTime];
					
					InMulDivX = Insts[minInputTime][8:6];
					InLabelMulDiv = minInputTime;
					RUNMulDiv = 1;
				end
			end
		end
	end

	registradorD r0(clk,newData,updateData[0],newLabel,updateLabel[0],Tags[0],Regs[0]);
	registradorD r1(clk,newData,updateData[1],newLabel,updateLabel[1],Tags[1],Regs[1]);
	registradorD r2(clk,newData,updateData[2],newLabel,updateLabel[2],Tags[2],Regs[2]);
	registradorD r3(clk,newData,updateData[3],newLabel,updateLabel[3],Tags[3],Regs[3]);
	Count_tomasulo my_time(clk,Time);
	FU_add_sub FU_add(clk,Runaddsum,RegAddSubX,RegAddSubY,AddSubOp,ResultAddSub,DoneAddSub,InputX_AddSub,InLabelAddSub,AddressAddSubX,LabelAddSub);
	FU_mul_div FU_mul(clk,RUNMulDiv,RegMulDivX,RegMulDivY,OpMulDiv,ResultMulDiv,DoneMulDiv,InMulDivX,InLabelMulDiv,AddressMulDivX,LabelMulDiv);
	iQueue instrucoes(clk,0,InInst,AddSubFull,MulDivFull);
	
endmodule