Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verilog binary addition

Binary addition on A and B and outputs it along with proper carry bit. I'm not sure how to implement the carry bit

A and B are 4 bit inputs

C is 1 bit output that is used for the carry bit

module addop(C , O , A , B);
   input [3:0] A;
   input [3:0] B;
   output [3:0] O;
   output       C;

   assign C1 = A[0] + B[0];
   assign C2 = A[0] + B[1];
endmodule

1 Answers

You may want to use a concatenation operator {} here.

module addop(C, O, A, B);
   input [3:0] A;
   input [3:0] B;
   output [3:0] O;
   output       C;

   assign {C, O} = A + B;
endmodule

Your synthesis tool will be responsible in converting them into logic gates.

See this question which is related to concatenation:

What do curly braces mean in Verilog?

like image 153
e19293001 Avatar answered Jun 02 '26 00:06

e19293001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!