当前位置:   article > 正文

四位行波进位加法器的设计(vcs+verdi仿真)_四位行波加法器

四位行波加法器

四位行波进位加法器相当于四个全加器的级联

先设计全加器fa.v

  1. module fa(a, b, ci, sum, cout);
  2. input a, b, ci;
  3. output sum, cout;
  4. assign {cout, sum} = a + b + ci;
  5. endmodule

四位加法器add4.v

  1. module add4(a, b, ci, s, cout);
  2. input [3:0] a, b;
  3. input ci;
  4. output cout;
  5. output [3:0] s;
  6. wire [3:1] co;
  7. fa u1(a[0], b[0], ci, s[0], co[1]);
  8. fa u2(a[1], b[1], co[1], s[1], co[2]);
  9. fa u3(a[2], b[2], co[2], s[2], co[3]);
  10. fa u4(a[3], b[3], co[3], s[3], cout);
  11. endmodule

 add4tb.v

  1. `timescale 1ns/1ns
  2. module add4tb;
  3. reg [3:0] a_test, b_test;
  4. wire [3:0] sum_test;
  5. reg cin_test;
  6. wire cout_test;
  7. reg [9:0] test;
  8. integer error_count;
  9. add4 u1( .a(a_test), .b(b_test), .ci(cin_test), .s(sum_test), .cout(cout_test) );
  10. initial
  11. begin
  12. error_count = 0;
  13. `ifdef vcdplusdump
  14. $display("\n*** VCD+ file dump is turned on ***\n");
  15. $vcdpluson;
  16. #1000;
  17. $vcdplusoff;
  18. `endif
  19. `ifdef vcddump
  20. $display("\n*** VCD file dump is turned on ***\n");
  21. $dumpvars;
  22. // #1000;
  23. // $dumpoff;
  24. `endif
  25. `ifdef fsdbdump
  26. $display("\n*** fsdb file dump is turned on ***\n");
  27. $fsdbDumpfile("add4.fsdb");
  28. $fsdbDumpvars(0);
  29. // #1000
  30. // $fsdbDumpoff;
  31. `endif
  32. end
  33. initial
  34. begin
  35. for (test = 0; test <= 9'h1ff; test = test +1) begin
  36. cin_test = test[8];
  37. a_test = test[7:4];
  38. b_test = test[3:0];
  39. #50
  40. if ({cout_test, sum_test} !== (a_test + b_test + cin_test)) begin
  41. error_count = error_count + 1;
  42. if (error_count <= 10) begin
  43. $display("***ERROR at time = %0d ***", $time);
  44. $display("a = %h, b = %h, sum = %h; cin = %h, cout = %h",
  45. a_test, b_test, sum_test, cin_test, cout_test);
  46. end
  47. if (error_count == 10) begin
  48. $display("\n\nError count reached 10, subsequent error messages are suppressed");
  49. `ifdef vcdplusdump
  50. $vcdplusoff;
  51. $vcdplusdeltacycleoff;
  52. $vcdplusglitchoff;
  53. `endif
  54. `ifdef vcddump
  55. $dumpoff;
  56. `endif
  57. `ifdef fsdbdump
  58. $fsdbDumpoff;
  59. `endif
  60. end
  61. end
  62. #50;
  63. end
  64. if (error_count == 0)
  65. $display("*** Testbench Successfully Completed! ***");
  66. else begin
  67. $display("\n*********************************************");
  68. $display("*** Testbench completed with %0d errors ***",error_count);
  69. $display("*********************************************\n\n");
  70. end
  71. $finish;
  72. end
  73. endmodule

Verdi仿真结果 

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

闽ICP备14008679号