Verilog Code for BCD Adder

BCD Adder:

A 4-bit binary adder that is capable of adding two 4bit words having a BCD (binary-coded decimal) format. The result of the addition is a BCD-format 4-bit output word, representing the decimal sum of the addend and augend, and a carry that is generated if this sum exceeds a decimal value of 9. 
  
We have implemented a 4-bit BCD adder using 1-bit full adder, AND, OR gate. Three inputs are taken as a, b, cin and three outputs are produced as sum, carry and cout.

Verilog Code for BCD Adder: 

module bcd_adder(sum,cout,a,b,cin);
output reg [3:0]sum;//4bit sum output.
output reg cout;//carry output.
input [3:0]a,b;//4bit input a and b.
input cin;//carry input.

always@(*)
begin
sum=a+b+cin;//here we are adding a , b and c .
if(sum>9) begin//if sum is greater then we will add 6.
sum = sum +6;
cout = 1;//and carry become 1.
end
else begin
cout = 0;
sum = sum;
end
end
endmodule

OUTPUT:


Post a Comment

0 Comments