The "ripple carry" adder for binary numbers

  • The ripple carry adder circuit is a simple (but less efficient) digital circuit to perform addition of binary number

  • The design of the ripple carry adder is based on binary number additions:

                       CarryIn = 1            
                       <--- 
               1      1      1
            +  1      0      1
          -------------------------
                   
      

    In order to add a pair of corresponding bits, we only need to know whether the addition of the previous pair produced a carry (=1)

The full adder circuit

  • The full adder digital circuit is a circuit that performs the addition of a corresponding pair of binary digits using a possible carry from the previous stage

  • The design of the full adder circuit is based on the binary number addition:

             CarryOut   CarryIn = 0 or 1            
                 <---  <--- 
               ?      1      ?
            +  ?      0      ?
          -------------------------
                    Sum-Bit
      

    The full adder has these inputs: 2 input bits and a CarryIn bit
    The full adder has these outputs: a Sum bit and a CarryOut bit

Operation of the full adder circuit

The full adder performs the addition of 2 corresponding bits (a and b) with a carry indication cin:

The sum output s = the sum result of the addition of a, b and cin
The cout output = 1 if the addition produced a carry (and = 0 otherwise)

Designing the full adder circuit
 

The logic table of the full adder circuit is as follows:

        (inputs)      (outputs)
       cin  a   b  |   cout  s
      -------------+----------
       0    0   0  |   0    0
       0    0   1  |   0    1
       0    1   0  |   0    1 
       0    1   1  |   1    0
       1    0   0  |   0    1
       1    0   1  |   1    0
       1    1   0  |   1    0
       1    1   1  |   1    1
  
   

We could use the digital circuit design method to construct a (non-optimal) full adder circuit..

The optimal circuit for a full adder
 

Because the full adder is a very important circuit, we have found the optimal solution:

DEMO: /home/cs355001/demo/circuits/1-full-adder.m

The ripple carry adder
 

  • The ripple carry adder is a digital circuit constructed using full adder circuits used to perform addition of binary numbers

  • The ripple carry adder circuit is based on how humans perform binary number additions:

      • Add the corresponding pairs of binary digits from right to left

      • Perform the addition on one pair of binary numbers at a time

 

I will now show the design of a ripple carry adder to add binary numbers of (upto) 4 bits

The design can be easily generalized for binary numbers of any number of bits

The ripple carry ader for binary numbers of (upto) 4 bits
 

The 4 bits ripple carry adder adds two 4-bits (binary) numbers ( a3a2a1a0 +b b3b2b1b0 ):

The sum of the addition is s3s2s1s0
And cout = 1 if the addition produced a carry output (and cout = 0 otherwise)

The ripple carry ader for binary numbers of (upto) 4 bits
 

We start with putting down the inputs and outputs of the circuit:

 

The ripple carry ader for binary numbers of (upto) 4 bits
 

Add the last pair of binary digits using one full adder circuit:

The Carry Input = 0 because there were no previous additions !

The ripple carry ader for binary numbers of (upto) 4 bits
 

Then: add the next pair of binary digits using the carry from the previous full adder:

 

The ripple carry ader for binary numbers of (upto) 4 bits
 

Next: add the next pair of binary digits using the carry from the previous full adder:

 

The ripple carry ader for binary numbers of (upto) 4 bits
 

Finally: add the last pair of binary digits using the carry from the previous full adder:

DEMO: /home/cs355001/demo/circuits/4-bit-adder.m

Using a user-defined component to construct another user-defined component

  • Do take a look inside /home/cs355001/demo/circuits/4-bit-adder.m:

      Define Full_Adder CarryIn a b | CarryOut Sum;
        Xor aa a b x;
        Xor ab x CarryIn Sum;
        And bb a b y;
        And cb CarryIn x z;
        Or bc-cc y z CarryOut;
      Endef;
      
      Define FourBit_Adder   a3 a2 a1 a0 b3 b2 b1 b0 | CarryOut s3 s2 s1 s0;
         Full_Adder ch ZERO  a0 b0  | c1       s0;
         Full_Adder cf c1    a1 b1  | c2       s1;
         Full_Adder cd c2    a2 b2  | c3       s2;
         Full_Adder cb c3    a3 b3  | CarryOut s3;
      Endef;
      

  • This circuit program shows that you can use a user-defined circuit component to construct another user-defined circuit component !!!

    Syntax rule: you must define a user-defined component before you can use it

The constant inputs ZERO and ONE in EDiSim
 

  • If an input value for a circuit is always constant (= not changing), you can use the keyword ONE as input signal 1

    And use ZERO if the input is always equal to 0

    Example:

      Define FourBit_Adder   a3 a2 a1 a0 b3 b2 b1 b0 | CarryOut s3 s2 s1 s0;
         Full_Adder ch ZERO  a0 b0  | c1       s0;
         Full_Adder cf c1    a1 b1  | c2       s1;
         Full_Adder cd c2    a2 b2  | c3       s2;
         Full_Adder cb c3    a3 b3  | CarryOut s3;
      Endef;
      

The array signal notation in EDiSim

  • From now on, you will often use binary numbers as input/output like this:

       a7 a6 a5 a4 a3 a2 a1 a0 // = an 8 bits binary number 
      

    (We always put the most significant (binary) digit at the left (e.g.: 10001001)

  • There is a shorter array notation available in EDiSim syntax:

       a[7..0] or a[7-0] ≡ a[7] a[6] a[5] a[4] a[3] a[2] a[1] a[0] 
      

    The signal names defined by a[7..0] (or: a[7-0]) are a[7], a[6], ..., a[0]

    (So use a[0] and not: a0, they are different signal names !!)

Example using the array signal notation
 

Previously, you saw the 4-bit-adder circuit in EDiSim code using non-array signal notation:

Define FourBit_Adder   a3 a2 a1 a0 b3 b2 b1 b0 | CarryOut s3 s2 s1 s0;
   Full_Adder ch ZERO  a0 b0  | c1       s0;
   Full_Adder cf c1    a1 b1  | c2       s1;
   Full_Adder cd c2    a2 b2  | c3       s2;
   Full_Adder cb c3    a3 b3  | CarryOut s3;
Endef;
  

It is rather cumbersome to write a long series of digits

Example using the array signal notation
 

Using the array signal notation of EDiSim, the same circuit can be re-written more succinctly as:

Define FourBit_Adder   a[3..0] b[3..0] | CarryOut s[3..0];
   Full_Adder ch ZERO  a[0] b[0]  | c1       s[0];
   Full_Adder cf c1    a[1] b[1]  | c2       s[1];
   Full_Adder cd c2    a[2] b[2]  | c3       s[2];
   Full_Adder cb c3    a[3] b[3]  | CarryOut s[3];
Endef;
  

Note that we must change a0 ⇒ a[0], a1 ⇒ a[1], ... b0 ⇒ b[0], b1 ⇒ b[1],... s0 ⇒ s[0], s1 ⇒ s[1],... inside the body of the definition !!!

(Because:   a0 ≠ a[0], a1 ≠ a[1], ... b0 ≠ b[0], b1 ≠ b[1],... s0 ≠ s[0], s1 ≠ s[1],... !!!)

DEMO: /home/cs355001/demo/circuits/4-bit-adder.arr