BEHAVIORAL DESCRIPTION
module encoder8_3 (y, I);
input [7:0] I;
output [2:0] y;
reg [2:0] y;
always @(I)
begin
case (I)
8'b0000_0001: y = 3'b000;
8'b0000_0010: y = 3'b001;
8'b0000_0100: y = 3'b010;
8'b0000_1000: y = 3'b011;
8'b0001_0000: y = 3'b100;
8'b0010_0000: y = 3'b101;
8'b0100_0000: y = 3'b110;
8'b1000_0000: y = 3'b111;
default: y = 3'bxxx; // undefined if multiple inputs high
endcase
end
endmodule
Test Bench:--
module tb_encoder8_3;
reg [7:0] I;
wire [2:0] y;
// Instantiate the 8:3 encoder
encoder8_3 uut (.y(y), .I(I));
initial
begin
I = 8'b0000_0001; // input 0
#10 I = 8'b0000_0010; // input 1
#10 I = 8'b0000_0100; // input 2
#10 I = 8'b0000_1000; // input 3
#10 I = 8'b0001_0000; // input 4
#10 I = 8'b0010_0000; // input 5
#10 I = 8'b0100_0000; // input 6
#10 I = 8'b1000_0000; // input 7
#20 $finish;
end
endmodule
OUTPUT