-
The
ripple_carry_adder
module takes two 32-bit inputsA
andB
and produces a 32-bit sum outputsum
along with the carry-outcarry_out
. -
We use a generate loop to instantiate 32 instances of the
full_adder
module, connecting them in a ripple carry fashion. Each instance of thefull_adder
module computes the sum and carry-out for one bit position. -
The
full_adder
module takes three inputsA
,B
, andCi
(carry-in) and produces two outputsS
(sum) andCo
(carry-out).
This code models a 32-bit ripple carry adder using full adders, which is a simple but slow method of adding two numbers. For more efficient addition of large numbers, you might consider using other adder structures like a carry-lookahead adder or carry-skip adder.
- Case 1 tests the addition of
0xABCDEF01
and0x12345678
. - Case 2 tests the addition of
0xFFFFFFFF
and0x00000001
.
You can add more test cases by following a similar structure. Each case sets the input values A
and B
, waits for some simulation time to allow the computation to finish, and then displays the results.
Make sure to extend the testbench with more test cases and adjust the initial values of A
and B
as needed to cover the desired scenarios.