题解 | #优先编码器Ⅰ#
优先编码器Ⅰ
https://www.nowcoder.com/practice/a7068b8f4c824d6a9592f691990b21de
`timescale 1ns/1ns
module encoder_83(
input [7:0] I ,
input EI ,
output wire [2:0] Y ,
output wire GS ,
output wire EO
);
//从功能表中可以看到,当EI 为0的时候,输出为0,
//当EI为1的时候,如果I==8'h0,则输出依旧为0
//当8-3译码,输入为8’h01的时候,输出同样为0,
//于是需要标志位EO以及GS,来表示何种情况,
//如果是EI==1,且I==8'h0,此时EO=1表示
//如果EI==1,且I!=0,此时GS=1;
reg[3:0] Y_temp;
always@(*)begin
casez(I)
8'h00:Y_temp=3'h0;
8'b1???_????:Y_temp=3'h7;
8'b01??_????:Y_temp=3'h6;
8'b001?_????:Y_temp=3'h5;
8'b0001_????:Y_temp=3'h4;
8'b0000_1???:Y_temp=3'h3;
8'b0000_01??:Y_temp=3'h2;
8'b0000_001?:Y_temp=3'h1;
8'b0000_0001:Y_temp=3'h0;
endcase
end
assign Y=EI?Y_temp:3'h0;
assign GS=EI==1 && I!=0;
assign EO=EI==1 && I==0;
endmodule
查看19道真题和解析