Advertisement
Guest User

Untitled

a guest
May 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // adder_tb.v
  2.  
  3. // 4-bit Adder Testbench
  4.  
  5. // ------------------------------------------------------------------
  6. // Copyright (c) 2006 Susan Lysecky, University of Arizona
  7. // Permission to copy is granted provided that this header remains
  8. // intact. This software is provided with no warranties.
  9. // ------------------------------------------------------------------
  10.  
  11. `timescale 1ns / 1ps
  12.  
  13. module Adder(A, B, Result);
  14.  
  15. input [3:0] A;
  16. input [3:0] B;
  17. output [3:0] Result;
  18. reg [3:0] Result;
  19.  
  20. always @ (A or B)
  21. begin
  22.  
  23. Result <= A + B;
  24. end
  25.  
  26. endmodule
  27.  
  28.  
  29. module Testbench;
  30.  
  31. reg [3:0] A_t;
  32. reg [3:0] B_t;
  33. wire [3:0] Result_t;
  34.  
  35. Adder Adder_1(A_t, B_t, Result_t);
  36.  
  37. initial
  38. begin
  39.  
  40. //case 0
  41. A_t <= 0; B_t <= 0;
  42. #1 $display("Result_t = %b", Result_t);
  43.  
  44. //case 1
  45. A_t <= 6; B_t <= 1;
  46. #1 $display("Result_t = %b", Result_t);
  47.  
  48. //case 2
  49. A_t <= 1; B_t <= 0;
  50. #1 $display("Result_t = %b", Result_t);
  51.  
  52. //case 3 (overflow should occur)
  53. A_t <= 10; B_t <= 10;
  54. #1 $display("Result_t = %b", Result_t);
  55.  
  56. end
  57. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement