Bugs mux2
此 8 位宽 2 对 1 多路复用器不工作。修复错误。
代码如下:
module top_module (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out );
//assign out = (~sel & a) | (sel & b);按位与
assign out = sel ? a : b;
endmodule
Bugs nand3
这个三输入 NAND 门不起作用。修复错误。
您必须使用提供的 5 输入 AND 门:
module andgate ( output out, input a, input b, input c, input d, input e );
代码如下:
module top_module (input a, input b, input c, output out);//
wire outt;
//andgate inst1 ( a, b, c, out );例化操作
andgate inst1 (outt, a, b, c, 1'b1, 1'b1);
assign out = ~outt;
endmodule
Bugs mux4
此 4 对 1 多路复用器不起作用。修复错误。
为您提供无错误的 2 对 1 多路复用器:
module mux2 (
input sel,
input [7:0] a,
input [7:0] b,
output [7:0] out
);
代码如下:
module top_module (
input [1:0] sel,
input [7:0] a,
input [7:0] b,
input [7:0] c,
input [7:0] d,
output [7:0] out ); //
/*
1、线的名称和模块例化的名称应该不一样;
2、定义线的位宽应改为8位;
3、sel[1]
wire mux0, mux1;
mux2 mux0 ( sel[0], a, b, mux0 );
mux2 mux1 ( sel[1], c, d, mux1 );
mux2 mux2 ( sel[1], mux0, mux1, out );*/
wire [7:0] mux0, mux1;
mux2 mux_0 ( sel[0], a, b, mux0 );
mux2 mux_1 ( sel[0], c, d, mux1 );
mux2 mux_2 ( sel[1], mux0, mux1, out );
endmodule
Bugs addsubz
以下带有零标志的加法器-减法器不起作用。修复错误。
代码如下:
// synthesis verilog_input_version verilog_2001
module top_module (
input do_sub,
input [7:0] a,
input [7:0] b,
output reg [7:0] out,
output reg result_is_zero
);//
always @(*) begin
case (do_sub)
0: out = a+b;
1: out = a-b;
endcase
//锁存器
if (!out)
result_is_zero = 1;
else
result_is_zero = 0;
end
endmodule
Bugs case
这个组合电路应该识别键 0 到 9 的 8 位键盘扫描码。它应指示 10 个案例中的一个是否被识别(有效),如果是,则检测到哪个密钥。修复错误。
代码如下:
module top_module (
input [7:0] code,
output reg [3:0] out,
output reg valid );//
always @(*)begin
out = 0;
valid = 1;
case (code)
8'h45: out = 0;
8'h16: out = 1;
8'h1e: out = 2;
8'h26: out = 3;
8'h25: out = 4;
8'h2e: out = 5;
8'h36: out = 6;
8'h3d: out = 7;
8'h3e: out = 8;
8'h46: out = 9;
default: valid = 0;
endcase
end
endmodule