题解 | #优先编码器Ⅰ#
优先编码器Ⅰ
https://www.nowcoder.com/practice/a7068b8f4c824d6a9592f691990b21de
`timescale 1ns/1ns module encoder_83( input [7:0] I , input EI , output reg [2:0] Y , output reg GS , output reg EO ); always @(*) begin if(!EI) begin Y = 3'b0 ; end else begin casex(I) 8'b0000_0000 : Y = 3'b000 ; 8'b1xxx_xxxx : Y = 3'b111 ; 8'b01xx_xxxx : Y = 3'b110 ; 8'b001x_xxxx : Y = 3'b101 ; 8'b0001_xxxx : Y = 3'b100 ; 8'b0000_1xxx : Y = 3'b011 ; 8'b0000_01xx : Y = 3'b010 ; 8'b0000_001x : Y = 3'b001 ; 8'b0000_0001 : Y = 3'b000 ; endcase end end always @(*) begin if(EI && (I == 8'b0)) EO = 1'b1 ; else EO = 1'b0 ; end always @(*) begin if(!EI) GS = 1'b0 ; else begin if( I == 8'b0) GS = 1'b0 ; else GS = 1'b1 ; end end endmodule