Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module full_adder (input A, B, Cin, output S, Cout);
- assign S = A ^ B ^ Cin;
- assign Cout = A & B | A & Cin | B & Cin;
- /*
- Mismo circuito, pero en un bloque 'always'. Lo dejo aquí como referencia únicamente.
- reg rS, rCout;
- always @ (A or B) begin
- rS = A ^ B ^ Cin;
- rCout = A & B | A & Cin | B & Cin;
- end
- assign S = rS;
- assign Cout = rCout;
- */
- endmodule
- module testbench();
- reg A, B, Cin;
- wire S, Cout;
- full_adder U1(A, B, Cin, S, Cout);
- initial begin
- $display("Cin A B | S Cout");
- $display("----------------");
- $monitor(" %b %b %b | %b %b", Cin, A, B, S, Cout);
- Cin = 0; A = 0; B = 0;
- #1
- Cin = 0; A = 0; B = 1;
- #1
- Cin = 0; A = 1; B = 0;
- #1
- Cin = 0; A = 1; B = 1;
- #1
- Cin = 1; A = 0; B = 0;
- #1
- Cin = 1; A = 0; B = 1;
- #1
- Cin = 1; A = 1; B = 0;
- #1
- Cin = 1; A = 1; B = 1;
- #1
- $finish;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement