3

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
Brad Larson
  • 170,088
  • 45
  • 397
  • 571

1 Answers1

6

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?

Community
  • 1
  • 1
e19293001
  • 2,783
  • 9
  • 42
  • 54