题解 | 优先编码器Ⅰ
`timescale 1ns/1ns module encoder_83( input [7:0] I , input EI , output wire [2:0] Y , output wire GS , output wire EO ); //I[i]=1 则Y=i //任意I[i]=1,GS=1 //EI=1时,输出有效 //EI=1 无输入时, EO有效 assign Y = EI? (I == 8'b0000_0001)?3'd0 : (I[7:1] == 7'b0000_001 )?3'd1 : (I[7:2] == 6'b0000_01 )?3'd2 : (I[7:3] == 5'b0000_1 )?3'd3 : (I[7:4] == 4'b0001 )?3'd4 : (I[7:5] == 3'b001 )?3'd5 : (I[7:6] == 2'b01 )?3'd6 : (I[7 ] == 1'b1 )?3'd7 : 3'd0 : 3'd0; assign GS = EI & |I; assign EO = EI & ~|I; endmodule