|
module compare(A,B,C,Max,Min,Med);
parameter width=8;
input [width-1:0] A,B,C;
output[width-1:0] Max,Min,Med;
reg [width-1:0] Max,Min,Med;
reg[1:0] a,b,c;
always @(A or B or C)
begin
if(A>B)
a=2'b10;
else if (A<B)
a=2'b00;
else a=2'b01;
if (B>C)
b=2'b10;
else if (B<C)
b=2'b00;
else
b=2'b01;
if(A>C)
c=2'b10;
else if (A<C)
c=2'b00;
else
c=2'b01;
case({a,b,c})
6'b101010: begin
Max=A; Med=B; Min=C;
end //A>B>C
6'b100010: begin
Max=A; Med=C; Min=B;
end //A>C>B
6'b100000: begin
Max=C; Med=A; Min=B;
end //C>A>B
6'b100001: begin
Max=A;Med=A;Min=B;
end //A=C>B
6'b100110: begin
Max=A;Med=B;Min=B;
end //A>B=C
6'b001010: begin
Max=B;Med=A; Min=C;
end //B>A>C
6'b001000: begin
Max=B; Med=C; Min=A;
end //B>C>A
6'b000101: begin
Max=B;Med=C;Min=C;
end //B>A=C;
6'b000000: begin
Max=C;Med=B;Min=A;
end //C>B>A
6'b000100: begin
Max=C;Med=C;Min=A;
end //C=B>A
6'b011010: begin
Max=A;Med=A;Min=C;
end //A=B>C
6'b010000: begin
Max=C;Med=A;Min=A;
end //C>A=B
6'b010101: begin
Max=A;Med=A;Min=A;
end //A=B=C
default: begin
Max=0;Med=0;Min=0;
end //$display("there is an error in the input data!");
endcase
end
endmodule |
|