Advertisement
LockdateforGHS

Untitled

Jun 25th, 2023
2,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module FullAdder (
  2.   input logic a,
  3.   input logic b,
  4.   input logic carryIn,
  5.   output logic sum,
  6.   output logic carryOut
  7. );
  8.   // Full Adder logic
  9.   assign sum = a ^ b ^ carryIn;
  10.   assign carryOut = (a & b) | (carryIn & (a ^ b));
  11. endmodule
  12.  
  13. module FullAdderTestbench;
  14.   logic a, b, carryIn;
  15.   logic sum, carryOut;
  16.  
  17.   // Instantiate FullAdder module
  18.   FullAdder dut (
  19.     .a(a),
  20.     .b(b),
  21.     .carryIn(carryIn),
  22.     .sum(sum),
  23.     .carryOut(carryOut)
  24.   );
  25.  
  26.   initial begin
  27.     // Testcase 1
  28.     a = 1'b0;
  29.     b = 1'b0;
  30.     carryIn = 1'b0;
  31.     #10;
  32.     $display("Testcase 1: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
  33.    
  34.     // Testcase 2
  35.     a = 1'b1;
  36.     b = 1'b0;
  37.     carryIn = 1'b0;
  38.     #10;
  39.     $display("Testcase 2: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
  40.    
  41.     // Testcase 3
  42.     a = 1'b1;
  43.     b = 1'b1;
  44.     carryIn = 1'b1;
  45.     #10;
  46.     $display("Testcase 3: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
  47.    
  48.     // End simulation
  49.     $finish;
  50.   end
  51. endmodule
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement