www.pudn.com > sort.rar > sort.v, change:2011-02-21,size:3524b


 `timescale  1 ps / 1 ps
module comparator_mdf(
   clk,
   rst_n,
   input_1,
   input_2,
   input_3, 
   max,
   min,
   median
);

input         clk;
input         rst_n;
input  signed [11:0]  input_1;
input  signed [11:0]  input_2;
input  signed [11:0]  input_3;

output signed[11:0]  max;
output signed[11:0]  min;
output signed[11:0]  median;


reg  signed[11:0]  max;
reg  signed[11:0]  min;
reg  signed[11:0]  median;


always @(posedge clk or negedge rst_n)
  begin
    if(!rst_n)
      begin
        max <=0;
        median <=0;
        min <=0;
      end
    else
      begin
      if(input_1>input_2)
      		begin
      		if(input_2>input_3)
      				begin
      				   max <=input_1;
        				 median <=input_2;
       					 min <=input_3;
      				end
      		else if(input_2==input_3)
      							begin
			      				   max <=input_1;
			        				 median <=input_2;
			       					 min <=input_3;      							
      							end
      		else if(input_2<input_3)
      							begin
      							if(input_3>input_1)
      									begin
					      				   max <=input_3;
					        				 median <=input_1;
					       					 min <=input_2;      									
      									end
      							else if(input_3==input_1)
      											begin
							      					max <=input_1;
							        				 median <=input_3;
							       					 min <=input_2;
      											end
      							else if(input_3<input_1)
      											begin
							      				   max <=input_1;
							        				 median <=input_3;
							       					 min <=input_2;      											
      											end						
      							end							
      		end
      else if(input_1<input_2)
      		 		 begin
      		 		 		if(input_2>input_3)
      		 		 				begin
      		 		 								if(input_1<input_3)
      		 		 										begin
										      		 		 	 max <=input_2;
										        				 median <=input_3;
										       					 min <=input_1;
      		 		 										end
      		 		 								else if(input_1==input_3)
      		 		 													begin
													      		 		 	 max <=input_2;
													        				 median <=input_1;
													       					 min <=input_3;
      		 		 													end
      		 		 								else if(input_1>input_3)
      		 		 													begin
													      		 		 	max <=input_2;
													        				 median <=input_1;
													       					 min <=input_3;
      		 		 													end		
      		 		 				end
      		 		 		else if(input_2==input_3)
      		 		 							begin
							      		 		 	 max <=input_3;
							        				 median <=input_2;
							       					 min <=input_1;
      		 		 							end
      		 		 		else if(input_2<input_3)
      		 		 							begin
							      		 		 	 max <=input_3;
							        				 median <=input_2;
							       					 min <=input_1;			
      		 		 							end
      		 		 														
      		 		 end
      else if(input_1==input_2)
      					begin
      						if(input_2>input_3)
      								begin
				      					max <=input_1;
				        				 median <=input_2;
				       					 min <=input_3;
      								end
      						else if(input_2==input_3)
      											begin
							      					 max <=input_1;
							        				 median <=input_2;
							       					 min <=input_3;
      											end
      						else if(input_2<input_3)
      											begin
							      					 max <=input_3;
							        				 median <=input_1;
							       					 min <=input_2;
      											end					
      					end		 		 	
      
      end
end
 endmodule