设计一个4位*4位的乘法器
module mul(a,b,out);
input [3:0]a,b;
output [7:0]out;
wire [3:0]w0,w1,w2,w3;
w0 = a[0]?{4'b0,b}:8'b0;
w1 = a[1]?{3'b0,b,1'b0}:8'b0;
w2 = a[2]?{2'b0,b,2'b0}:8'b0;
w3 = a[3]?{1'b0,b,3'b0}:8'b0;
assign out = w0 + w1 + w2 + w3;
endmodule
至于乘法器为什么不直接用a*b得到out,需要有硬件思维去看,具体可以看: