当前位置:   article > 正文

Circuits--Verification--Finding Bug

Circuits--Verification--Finding Bug

1. MUX

  1. module top_module (
  2. input sel,
  3. input [7:0] a,
  4. input [7:0] b,
  5. output [7:0] out );
  6. assign out = sel ? a : b;
  7. endmodule

2.NAND

  1. module top_module (input a, input b, input c, output out);//
  2. wire t;
  3. andgate inst1 (t,a,b,c,1'b1,1'b1);
  4. assign out = ~t;
  5. endmodule

3. 4-1MUX

  1. module top_module (
  2. input [1:0] sel,
  3. input [7:0] a,
  4. input [7:0] b,
  5. input [7:0] c,
  6. input [7:0] d,
  7. output [7:0] out ); //
  8. wire [7:0]m0, m1;
  9. mux2 mux0 ( sel[0], a, b, m0 );
  10. mux2 mux1 ( sel[0], c, d, m1 );
  11. mux2 mux2 ( sel[1], m0, m1, out );
  12. endmodule

4.Add/Sub

  1. module top_module (
  2. input do_sub,
  3. input [7:0] a,
  4. input [7:0] b,
  5. output reg [7:0] out,
  6. output reg result_is_zero
  7. );//
  8. always @(*) begin
  9. case (do_sub)
  10. 0: out = a+b;
  11. 1: out = a-b;
  12. endcase
  13. end
  14. always@(*)
  15. begin
  16. if (out == 0)
  17. result_is_zero = 1;
  18. else
  19. result_is_zero = 0;
  20. end
  21. endmodule

5.Case Statement

  1. module top_module (
  2. input [7:0] code,
  3. output reg [3:0] out,
  4. output reg valid);//
  5. always @(*) begin
  6. case (code)
  7. 8'h45: out = 4'd0;
  8. 8'h16: out = 4'd1;
  9. 8'h1e: out = 4'd2;
  10. 8'h26: out = 4'd3;
  11. 8'h25: out = 4'd4;
  12. 8'h2e: out = 4'd5;
  13. 8'h36: out = 4'd6;
  14. 8'h3d: out = 4'd7;
  15. 8'h3e: out = 4'd8;
  16. 8'h46: out = 4'd9;
  17. default: out = 4'd0;
  18. endcase
  19. if(out == 4'd0 && code != 8'h45)
  20. valid = 1'b0;
  21. else
  22. valid = 1'b1;
  23. end
  24. endmodule

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/660728
推荐阅读
相关标签
  

闽ICP备14008679号