A ripple-carry adder builds an N-bit adder out of N single-bit full adders, chained so that each stage’s carry-out feeds the next stage’s carry-in. This is a classic example of building a larger circuit purely through structural instantiation of a smaller building block.
You are given a full_adder submodule (identical to the one you built earlier):
module full_adder (
input a,
input b,
input cin,
output sum,
output cout
);
assign sum = a ^ b ^ cin;
assign cout = (a & b) | (a & cin) | (b & cin);
endmodule
Build top_module with 4-bit inputs a and b, a carry-in cin, a 4-bit output sum, and a carry-out cout, implementing a 4-bit ripple-carry adder using four instances of full_adder.
Interface
| Signal | Direction | Width | Description |
|---|---|---|---|
a |
input | 4 | Operand |
b |
input | 4 | Operand |
cin |
input | 1 | Carry-in to bit 0 |
sum |
output | 4 | a + b + cin, truncated to 4 bits |
cout |
output | 1 | Carry-out of bit 3 |
Notes
- You will need three internal wires to carry the carry-out of stage 0 into stage 1, stage 1 into stage 2, and stage 2 into stage 3.
- The carry-in of the least-significant full adder is the module’s
cin; the carry-out of the most-significant full adder is the module’scout.