Verilog Code for 8bit Full Adder


Hola Amigos
Adders as we all have used might pose a problem when simulated for very long space complex projects as the results of full adder are not instant. It does take time and the propagation delay increases with time so how do we deal with delay caused by each gate. Here have a look on this basic adder

What we come to know about it is that for C4 we have to wait for C3, similarly for C3 we have to wait for C2. This causes delay and then there comes Carry Look Ahead Adder in limelight. 

One can increase the space complexity of the code to decrease the time for propagation or introduce just faster delays to decrease the propagation delay of the overall adder.

A basic full adder is a parallel adder which is based on complex circuit to directly induce the carry from the inputs provided.

Now S = Sum and C(-1) = carry from previous addition.
So S = EXOR(A,B,C) and 
C(0) = A.B + EXOR(A,B).C(-1)

Now let  A.B = Gi  and EXOR(A,B) = Pi

So        C0  = G0 + P0 . C-1

C1  = G1 + Pi . C0

C2  = G2 + Pi . C1

C3  = G3 + Pi . C2

C4  = G4 + Pi . C2

SUM = A’B’Cin + A’BC’in  + AB’C’In + ABCin  
Cout = BCin  + ACin + AB

Code for a 8 bit Full Adder

module FA(a,b,c,s,co);
input [7:0]a,b;
output [8:0]s;
output co;
input c;
Carry c1(a[0],b[0],c,s[0],cx0);
Carry c2(a[1],b[1],cx0,s[1],cx1);
Carry c3(a[2],b[2],cx1,s[2],cx2);
Carry c4(a[3],b[3],cx2,s[3],cx3);
Carry c5(a[4],b[4],cx3,s[4],cx4);
Carry c6(a[5],b[5],cx4,s[5],cx5);
Carry c7(a[6],b[6],cx5,s[6],cx6);
Carry c8(a[7],b[7],cx6,s[7],s[8]);
assign co = s[8];

module Carry(a,b,c,s,co);
input a,b;
input c;
output s,co;
wire out4;
wire out6;
and (out1,a,b);
xor (out2,a,b);
and (out3,out2,c);
or (out4,out3,out1);
assign co = out4;
xor (out5,a,b);
xor (out6,out5,c);
assign s = out6;

Here is the Test Bench 

module TestCarry;

          // Inputs
          reg [7:0] a;
          reg [7:0] b;
          reg c;
          wire [8:0] s;
          wire co;
          CLA uut (
          initial begin
                   // Initialize Inputs
                   a = 8'b01101010;
                   b = 8'b10111101;
                   c = 0;

Here is the output in action 

Here s[8:0] is the sum c is input carry co is the final carry a[7:0] and b[7:0] are the numbers

So Long


  1. I get the following error when running : error: Unknown module type: CLA
    2 error(s) during elaboration.
    *** These modules were missing:
    CLA referenced 1 times.
    Exit code expected: 0, received: 1

    1. Replace CLA with FA in testbench and try.
      Let me know the result

  2. can you plz send me this code in behavioral method instead of gate level..


Post a Comment

Popular posts from this blog

SPI Working with Verilog Code

Verilog Code for I2C Protocol

SR Flip Flop Verilog Code