Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module FullAdder (
- input logic a,
- input logic b,
- input logic carryIn,
- output logic sum,
- output logic carryOut
- );
- // Full Adder logic
- assign sum = a ^ b ^ carryIn;
- assign carryOut = (a & b) | (carryIn & (a ^ b));
- endmodule
- module FullAdderTestbench;
- logic a, b, carryIn;
- logic sum, carryOut;
- // Instantiate FullAdder module
- FullAdder dut (
- .a(a),
- .b(b),
- .carryIn(carryIn),
- .sum(sum),
- .carryOut(carryOut)
- );
- initial begin
- // Testcase 1
- a = 1'b0;
- b = 1'b0;
- carryIn = 1'b0;
- #10;
- $display("Testcase 1: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
- // Testcase 2
- a = 1'b1;
- b = 1'b0;
- carryIn = 1'b0;
- #10;
- $display("Testcase 2: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
- // Testcase 3
- a = 1'b1;
- b = 1'b1;
- carryIn = 1'b1;
- #10;
- $display("Testcase 3: a=%b, b=%b, carryIn=%b, sum=%b, carryOut=%b", a, b, carryIn, sum, carryOut);
- // End simulation
- $finish;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement