verilog HDLBits刷题[Finding bugs in code]“Bugs mux2”---Mux
1、题目
2、分析
sel为1bit位宽数据
a和b作为输入都是8bit位宽,故out作为输出(根据sel,选择输出a或者输出b)应该也为8bit位宽
1 位sel和8位的a进行位运算,sel高位补 0 扩展成 8 位,相当于sel=8‘b0000_0001
3、改正代码
module top_module ( input sel, input [7:0] a, input [7:0] b, output [7:0]out ); assign out =sel?a:b; endmodule 或者 module top_module ( input sel, input [7:0] a, input [7:0] b, output [7:0]out ); assign out = ({8{sel}} & a) | (~{8{sel}} & b); endmodule4、结果
