Bugs mux2
原本代码的逻辑是反的,这不是坑人吗。- 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);
- endmodule
复制代码 Bugs nand3
五输入的与门现在要实现三输入的与非门,多余的门可以输入1并将输出取反。- module top_module (input a, input b, input c, output out);//
- wire out_n;
- andgate inst1 ( out_n,a, b, c, 1'b1,1'b1 );
- assign out = ~out_n;
- endmodule
复制代码 Bugs mux4
bug1:mux0和mux1的位宽没设置,默认是1;
bug2:选通引脚有问题,应该先通过mux[0]判断是ac还是bd,再通过mux[1]进行判断。- 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 ); //
- wire [7:0]mux0, mux1;
- mux2 u_mux0 ( sel[0], a, b, mux0 );
- mux2 u_mux1 ( sel[0], c, d, mux1 );
- mux2 u_mux2 ( sel[1], mux0, mux1, out );
- endmodule
复制代码 Bugs addsubz
verilog中~是按位取反,!是逻辑取反。
同时需要补充out不为0的情况,否则输出会默认保持,综合出latch。- // 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
这道题比较考验眼力,一个是d要改成h,还有一个是6位改成8位。晕。
还有就是先给两个输出赋默认值,就不会综合出latch了,而且代码也更加简洁。- module top_module (
- input [7:0] code,
- output reg [3:0] out,
- output reg valid );//
- always @(*)
- begin
- out = 0;
- valid = 1'b1;
- 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
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |