3-bit binary adder

Now that you know how to build a full adder, make 3 instances of it to create a 3-bit binary ripple-carry adder. The adder adds two 3-bit numbers and a carry-in to produce a 3-bit sum and carry out. To encourage you to actually instantiate full adders, also output the carry-out from each full adder in the ripple-carry adder. cout[2] is the final carry-out from the last full adder, and is the carry-out you usually see.

Adder3 - HDLBits (01xz.net)

1 module top_module( 
2     input [2:0] a, b,
3     input cin,
4     output [2:0] cout,
5     output [2:0] sum );
6     assign {cout[0],sum[0]} = a[0] + b[0] +cin;
7     assign {cout[1],sum[1]} = a[1] + b[1] +cout[0];
8     assign {cout[2],sum[2]} = a[2] + b[2] +cout[1];
9 endmodule

 

posted @ 2023-04-22 12:27  江左子固  阅读(32)  评论(0)    收藏  举报