SlideShare a Scribd company logo
1 of 79
UNIT 2
xi       yi          Carry­in ci             Sum s i     Carry­out c i+1
                                                                                                  At the ith stage:
           0        0           0                       0           0                             Input:
           0        0           1                       1           0                             ci is the carry-in
           0        1           0                       1           0
           0        1           1                       0           1                             Output:
           1        0           0                       1           0                             si is the sum
           1        0           1                       0           1
           1        1           0                       0           1                             ci+1 carry-out to (i+1)st
           1        1           1                       1           1                             state
             si   = xi yi ci + xi yi ci + xi yi ci + xi yi ci = x i ⊕ yi ⊕ ci
            ci +1 = yi c i + x i ci + x i y i



Example:


  X     7            0          1       1       1       Carry­out             xi       Carry­in
+ Y = + 6        = +00      1   1   1   1   0   0   0                         yi
                                                           ci+1                           ci
  Z    13            1          1       0       1                            si

                                                                    Legend for stage   i
Sum                                    Carry
                                        yi
                                        c
                                         i
     xi
                                        xi
     yi               si                            c
                                        c               i +1
                                             i
     ci
                                        x
                     xi            yi    i
                                        yi


            ci + 1    Full adder        ci
                        (FA)


                           s
                               i




Full Adder (FA): Symbol for the complete circuit
               for a single stage of addition.
•Cascade n full adder (FA) blocks to form a n-bit adder.
•Carries propagate or ripple through this cascade, n-bit ripple carry adder.


                     xn ­ 1        yn­ 1            x1        y1            x0        y0


                                           cn ­ 1                  c1
              cn              FA                         FA                      FA             c0



                          sn ­ 1                         s1                      s0
                   Most significant bit                                 Least significant bit
                    (MSB) position                                        (LSB) position




        Carry-in c0 into the LSB position provides a convenient way to
        perform subtraction.
K n-bit numbers can be added by cascading k n-bit adders.



                      xk n ­ 1 yk n ­ 1               x2n ­ 1 y2n ­ 1 xn y n           xn ­ 1 y n ­ 1 x 0 y 0


                                                                                  cn
                                  n­bit                           n­bit                          n­bit          c
               c kn                                                                                             0
                                  adder                           adder                          adder


                         s                s(              s               s               s              s
                             kn ­ 1        k ­ 1) n           2n ­ 1          n               n­ 1       0




Each n-bit adder forms a block, so this is cascading of blocks.
Carries ripple or propagate through blocks, Blocked Ripple Carry Adder
•Recall X – Y is equivalent to adding 2’s complement of Y to X.
•2’s complement is equivalent to 1’s complement + 1.
•X – Y = X + Y + 1
•2’s complement of positive and negative numbers is computed similarly.

                  xn ­ 1        yn­ 1            x1        y1            x0        y0


                                        cn ­ 1                  c1
           cn              FA                         FA                      FA             1



                       sn ­ 1                         s1                      s0
                Most significant bit                                 Least significant bit
                 (MSB) position                                        (LSB) position
y                  y       y
                                                    n­ 1               1       0
                                                                                       Add/Sub
                                                                                       control


        x            x              x
            n­ 1         1              0




c                                       n­bit adder
    n                                                                              c
                                                                                   0




                         s                      s          s
                             n­ 1                   1          0


             •Add/sub control = 0, addition.
             •Add/sub control = 1, subtraction.
Detecting overflows
 Overflows can only occur when the sign of the two operands is
  the same.
 Overflow occurs if the sign of the result is different from the
  sign of the operands.
 Recall that the MSB represents the sign.
    xn-1, yn-1, sn-1 represent the sign of operand x, operand y and result s
     respectively.
 Circuit to detect overflow can be implemented by the
  following logic expressions:

                     Overflow = xn −1 yn −1sn −1 + xn −1 yn −1sn −1

                             Overflow = cn ⊕ cn −1
x0        y0
                          Consider 0th stage:
                         •c1 is available after 2 gate delays.
                         •s1 is available after 1 gate delay.
c1        FA        c0



          s0

                         Sum                         Carry
                                          yi
                                          c
                                           i
                    xi
                                          xi
                    yi         si                            c
                                          c                      i +1
                                              i
                    ci
                                          x
                                           i
                                          yi
Cascade of 4 Full Adders, or a 4-bit adder

     x0         y0           x0        y0        x0        y0        x0        y0



          FA                      FA                  FA                  FA        c0
c4                      c3                  c2                  c1


           s3                     s2                  s1                  s0

          •s0 available after 1 gate delays, c1 available after 2 gate delays.
          •s1 available after 3 gate delays, c2 available after 4 gate delays.
          •s2 available after 5 gate delays, c3 available after 6 gate delays.
          •s3 available after 7 gate delays, c4 available after 8 gate delays.
          For an n-bit adder, sn-1 is available after 2n-1 gate delays
                           cn is available after 2n gate delays.
Recall the equations:

                  si = xi ⊕ yi ⊕ ci
                  ci +1 = xi yi + xi ci + yi ci
Second equation can be written as:

                   ci +1 = xi yi + ( xi + yi )ci
 We can write:
                 ci +1 = Gi + Pi ci
                 where Gi = xi yi and Pi = xi + yi

 •Gi is called generate function and Pi is called propagate function
 •Gi and Pi are computed only from xi and yi and not ci, thus they can
  be computed in one gate delay after X and Y are applied to the
 inputs of an n-bit adder.
ci +1 = Gi + Pi ci
  ci = Gi −1 + Pi −1ci −1
  ⇒ ci+1 = Gi + Pi (Gi −1 + Pi −1ci −1 )
  continuing
  ⇒ ci+1 = Gi + Pi (Gi −1 + Pi −1 (Gi − 2 + Pi− 2 ci −2 ))
  until
   ci+1 = Gi + PiGi −1 + Pi Pi−1 Gi −2 + .. + Pi Pi −1 ..P1G0 + Pi Pi −1 ...P0 c 0
•All carries can be obtained 3 gate delays after X, Y and c0 are applied.
     -One gate delay for Pi and Gi
    -Two gate delays in the AND-OR circuit for ci+1
•All sums can be obtained 1 gate delay after the carries are
computed.
•Independent of n, n-bit addition requires only 4 gate delays.
•This is called Carry Lookahead adder.
x       y                             x       y                        x       y                            x       y
              3       3                             2       2                        1       1                            0       0




c4
                              c
                                  3
                                                                    c
                                                                        2
                                                                                                         c
                                                                                                             1
                                                                                                                                          .   c
                                                                                                                                                      4-bit
                                                                                                                                                      carry-lookahead
          B cell                                B cell                           B cell                               B cell                      0

                                                                                                                                                      adder
                      s                                     s                                s                                    s
                          3                                     2                                1                                    0



     G3           P3                       G2           P2                  G            P                       G            P
                                                                             1               1                    0            0


                                                        Carry­lookahead logic
                                                        xi          yi


                                                        . .
                                                                             .                                        c
                                                                                                                          i


                                                                                                                                      B-cell for a single stage
                                                                                                     B cell




                                      Gi                            P   i
                                                                                 si
Carry lookahead adder (contd..)
 Performing n-bit addition in 4 gate delays independent of n
  is good only theoretically because of fan-in constraints.

    ci+1 = Gi + PiGi −1 + Pi Pi−1 Gi −2 + .. + Pi Pi −1 ..P1G0 + P Pi −1 ...P0 c0
                                                                  i

 Last AND gate and OR gate require a fan-in of (n+1) for a n-
  bit adder.
    For a 4-bit adder (n=4) fan-in of 5 is required.
    Practical limit for most gates.
 In order to add operands longer than 4 bits, we can cascade
  4-bit Carry-Lookahead adders. Cascade of Carry-Lookahead
  adders is called Blocked Carry-Lookahead adder.
Carry-out from a 4-bit block can be given as:
 c4 = G3 + P G2 + P3 P2 G1 + P3 P2 P G0 + P3 P2 P1P0 c0
            3                       1

Rewrite this as:

 P0I = P3 P2 P1 P0
G0I = G3 + P3 G2 + P3 P2 G1 + P3 P2 P1G0
Subscript I denotes the blocked carry lookahead and identifies the block.

Cascade 4 4-bit adders, c16 can be expressed as:

 c16 = G3 + P3I G2I + P3I P2I G1I + P3I P2I P10 G0 + P3I P2I P10 P00 c0
        I                                        I
x15­12    y15­12         x11­8    y11­8         x7­4       y7­4         x3­0     y3­0



c16        4­bit adder
                            c12
                                    4­bit adder
                                                   c8
                                                          4­bit adder
                                                                           c4
                                                                                  4­bit adder    .   c0


                  s15­12                   s11­8                   s7­4                  s3­0

         G3 I     P3 I            G2 I    P 2I          G 1I      P 1I          G 0I    P0 I


                                          Carry­lookahead logic


 After xi, yi and c0 are applied as inputs:
  - Gi and Pi for each stage are available after 1 gate delay.
  - PI is available after 2 and GI after 3 gate delays.
  - All carries are available after 5 gate delays.
  - c16 is available after 5 gate delays.
  - s15 which depends on c12 is available after 8 (5+3)gate delays
    (Recall that for a 4-bit carry lookahead adder, the last sum bit is
    available 3 gate delays after all inputs are available)
Product of 2 n-bit numbers is at most a 2n-bit number.
Unsigned multiplication can be viewed as addition of shifted
versions of the multiplicand.
Multiplication of unsigned
  numbers (contd..)
 We added the partial products at end.
   Alternative would be to add the partial products at each stage.

 Rules to implement multiplication are:
   If the ith bit of the multiplier is 1, shift the multiplicand and add the
    shifted multiplicand to the current value of the partial product.
   Hand over the partial product to the next stage
   Value of the partial product at the start stage is 0.
Typical multiplication cell


                     Bit of incoming partial product (PPi)
                                                               jth multiplicand bit

ith multiplier bit                                               ith multiplier bit



              carry out                   FA                  carry in



                           Bit of outgoing partial product (PP(i+1))
Combinatorial array multiplier
                                                                      Multiplicand
                                                0    m3 0        m2 0        m1 0        m0
                                       (PP0)
                                                                                         q0
                                                                                         0
                                     PP1                                            p0
                                                                             q1
                                                                             0




                                                                                     r
                                                                                  lie
                          PP2




                                                                               tip
                                                                        p1




                                                                             ul
                                                                 q2




                                                                             M
                                                                 0
               PP3                                          p2
                                                      q3
                                                      0
                                                                         ,
                p7   p6         p5         p4   p3



                                     Product is: p7,p6,..p0


Multiplicand is shifted by displacing it through an array of adders.
Combinatorial array multiplier
(contd..)
 Combinatorial array multipliers are:
   Extremely inefficient.
   Have a high gate count for multiplying numbers of practical size such as 32-
    bit or 64-bit numbers.
   Perform only one function, namely, unsigned integer product.

 Improve gate efficiency by using a mixture of
 combinatorial array techniques and sequential
 techniques requiring less combinational logic.
Sequential multiplication
 Recall the rule for generating partial products:
   If the ith bit of the multiplier is 1, add the appropriately shifted multiplicand
    to the current partial product.
   Multiplicand has been shifted left when added to the partial product.

 However, adding a left-shifted multiplicand to an
  unshifted partial product is equivalent to adding an
  unshifted multiplicand to a right-shifted partial
  product.
Register A  (initially 0)

                                                               Shift right

C       a                            a             q                            q
        n ­ 1                        0                 n­ 1                      0


                                                              Multiplier Q
                                              Add/Noadd
                                               control



n-bit
Adder
                           MUX                                               Control
                                                                             sequencer

    0                            0

            m                            m0
            n ­ 1


                Multiplicand M
M
    1   1   0   1
                                              Initial configuration
0   0   0   0   0             1   0   1   1
C        A                          Q
0   1   1   0   1             1   0   1   1        Add
                                                   Shift              First cycle
0   0   1   1   0             1   1   0   1

1   0   0   1   1             1   1   0   1        Add
                                                   Shift              Second cycle
0   1   0   0   1             1   1   1   0


0   1   0   0   1             1   1   1   0        No add
                                                   Shift              Third cycle
0   0   1   0   0             1   1   1   1

1   0   0   0   1             1   1   1   1        Add
                                                   Shift              Fourth cycle
0   1   0   0   0             1   1   1   1

                    Product
Signed Multiplication
 Considering 2’s-complement signed operands, what will happen to
  (-13)×(+11) if following the same method of unsigned multiplication?

                                                 1   0       0   1   1    ( ­ 13)
                                                 0   1       0   1   1   ( + 11)

                           1   1    1   1   1    1   0       0   1   1

                           1   1    1   1   1    0   0       1   1
       Sign extension is
        shown in blue      0   0    0   0   0    0   0       0

                           1   1    1   0   0    1   1

                           0   0    0   0   0    0

                           1   1    0   1   1    1   0       0   0   1   ( ­ 143)



                  Sign extension of negative multiplicand.
Signed Multiplication
 For a negative multiplier, a straightforward solution is
  to form the 2’s-complement of both the multiplier and
  the multiplicand and proceed as in the case of a
  positive multiplier.
 This is possible because complementation of both
  operands does not change the value or the sign of the
  product.
 A technique that works equally well for both negative
  and positive multipliers – Booth algorithm.
Signed Multiplication
Hardware Implementation
Booth Algorithm
Consider in a multiplication, the multiplier is positive
 0011110, how many appropriately shifted versions of
 the multiplicand are added in a standard procedure?

                                             0   1 0 1 1 0           1
                                             0   0 +1 +1 + 1+1       0
                                             0   0   0   0   0   0   0
                                         0   1   0   1   1   0   1
                                     0   1   0   1   1   0   1
                                 0   1   0   1   1   0   1
                             0   1   0   1   1   0   1
                         0   0   0   0   0   0   0
                     0   0   0   0   0   0   0
                 0   0   0   1   0   1   0   1   0   0   0   1   1   0
Booth Algorithm
 Since 0011110 = 0100000 – 0000010, if we use the
 expression to the right, what will happen?
                                         0 1     0   1   1 0     1
                                         0 +1    0   0   0 ­ 1   0
             0   0   0   0   0   0   0   0   0   0   0   0   0   0
                                                                     2's complement of
             1   1   1   1   1   1   1   0   1   0   0   1   1
                                                                     the multiplicand
             0   0   0   0   0   0   0   0   0   0   0   0
             0   0   0   0   0   0   0   0   0   0   0
             0   0   0   0   0   0   0   0   0   0
             0   0   0   1   0   1   1   0   1
             0   0   0   0   0   0   0   0
             0   0   0   1   0   1   0   1   0   0   0   1   1   0
Booth in the Booth scheme, -1 times the shifted multiplicand is
In general,
             Algorithm
    selected when moving from 0 to 1, and +1 times the shifted
    multiplicand is selected when moving from 1 to 0, as the multiplier
    is scanned from right to left.
          0   0   1   0   1   1   0   0   1   1   1   0   1   0   1   1   0   0



          0 +1 ­1 +1      0 ­ 1   0 +1    0   0 ­ 1 +1 ­ 1 + 1    0 ­ 1   0   0




                          Booth recoding of a multiplier.
Booth Algorithm
    0 1 1 0 1       ( + 13)                            0 1 1 0 1
   X1 1 0 1 0         (­ 6)                            0 ­ 1 +1 ­ 1 0
                                   0   0   0   0   0   0   0 0 0 0
                                   1   1   1   1   1   0   0 1 1
                                   0   0   0   0   1   1   0 1
                                   1   1   1   0   0   1   1
                                   0   0   0   0   0   0
                                   1 1 1 0 1 1 0 0 1 0                  ( ­ 78)



      Booth multiplication with a negative multiplier.
Booth Algorithm
        Multiplier
                          V ersion of multiplicand
                              selected by biti
       Bit i   Bit i ­1

        0          0              0 X M
        0          1            + 1 X M
        1          0            − 1 X M
        1          1              0 X M



     Booth multiplier recoding table.
Booth Algorithm
 Best case – a long string of 1’s (skipping over 1s)
 Worst case – 0’s and 1’s are alternating
                       0   1   0   1   0   1   0   1   0   1   0   1   0   1   0   1
         Worst­case
         multiplier
                      +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1




                       1   1   0   0   0   1   0   1   1   0   1   1   1   1   0   0
         Ordinary
         multiplier
                       0 ­1 0      0 + 1 ­ 1 +1    0 ­ 1 +1    0   0   0 ­1    0   0




                       0   0   0   0   1   1   1   1   1   0   0   0   0   1   1   1
          Good
         multiplier
                       0   0   0 +1    0   0   0   0 ­1    0   0   0 +1    0   0 ­1
Booth Algorithm
Flow Chart



                  Table
Bit-Pair Recoding of Multipliers
 Bit-pair recoding halves the maximum number of
 summands (versions of the multiplicand).
      Sign extension                                           Implied 0 to right of LSB
                        1    1   1    0    1   0    0



                        0    0   − 1 +1 − 1    0



                             0       −1        −2


        (a)  Example of bit­pair recoding derived from Booth recoding
Bit-Pair Recoding of Multipliers
      Multiplier bit­pair     Multiplier bit on the right       Multiplicand
                                                             selected at position i
       i+1          i                    i−1

         0          0                      0                         0   X  M
         0          0                      1                       +1    X  M
         0          1                      0                       +1    X  M
         0          1                      1                       +2    X  M
         1          0                      0                       −2    X  M
         1          0                      1                       −1     X  M
         1          1                      0                       −1     X  M
         1          1                      1                         0    X  M


                  (b) Table of multiplicand selection decisions
Bit-Pair Recoding of Multipliers                      0 1 1 0 1
                                                      0 ­ 1 +1 ­ 1 0
                                  0   0   0   0   0   0   0 0 0 0
                                  1   1   1   1   1   0   0 1 1
                                  0   0   0   0   1   1   0 1
                                  1   1   1   0   0   1   1
     0 1 1 0 1 ( + 13)            0   0   0   0   0   0
   × 1 1 0 1 0 (­ 6 )             1 1 1 0 1 1 0 0 1 0 ( ­ 78 )




                                                      0 1 1 0 1
                                                      0  ­1  ­2
                                  1 1 1 1 1 0 0 1 1 0
                                  1 1 1 1 0 0 1 1
                                  0 0 0 0 0 0
                                  1 1 1 0 1 1 0 0 1 0




                         Figure 6.15.  Multiplication requiring only n/2 summands.41
Carry-Save Addition of Summands
 CSA speeds up the addition process.




P7   P6        P5          P4           P3   P2   P1    P0
                                                       42
Carry-Save Addition of Summands(Cont.,)




P7   P6   P5   P4    P3     P2    P1       P0
Carry-Save Addition of
Summands(Cont.,)
  Consider the addition of many summands, we can:
  Group the summands in threes and perform carry-save addition on
   each of these groups in parallel to generate a set of S and C vectors in
   one full-adder delay
  Group all of the S and C vectors into threes, and perform carry-save
   addition on them, generating a further set of S and C vectors in one
   more full-adder delay
  Continue with this process until there are only two vectors remaining
  They can be added in a RCA or CLA to produce the desired product
Carry-Save Addition of Summands
                                    1    0   1    1   0    1          (45)          M

                                X   1    1   1    1   1    1          (63)          Q

                                    1    0   1    1   0    1           A
                                1   0    1   1    0   1                B

                           1    0   1    1   0    1                    C
                       1   0    1   1    0   1                         D
                  1    0   1    1   0    1                             E
              1   0    1   1    0   1                                  F

         1    0   1    1   0    0   0    1   0    0   1    1         (2,835)        Product




Figure 6.17.  A multiplication example used to illustrate carry­save addition as shown in Figure 6.18.
1   0   1   1   0   1   M

                          x 1   1   1   1   1   1   Q


                            1   0   1   1   0   1             A

                      1    0    1   1   0   1                 B

                  1   0     1   1   0   1                     C

                  1   1     0   0   0   0   1   1             S
                                                                  1
              0   0   1    1    1   1   0   0                 C
                                                                  1


              1   0   1    1    0   1                         D
          1   0   1   1    0    1                             E
      1   0   1   1   0     1                                 F

      1   1   0   0   0    0    1   1                         S
                                                                  2
  0   0   1   1   1   1    0    0                             C
                                                                  2

                  1   1     0   0   0   0   1   1             S1

              0   0   1    1    1   1   0   0                 C
                                                                  1
      1   1   0   0   0    0    1   1                         S2
      1   1   0   1   0     1   0   0   0   1   1             S
                                                                  3
  0   0   0   0   1   0     1   1   0   0   0                 C3
  0   0   1   1   1   1    0    0                             C2
  0   1   0   1   1   1    0    1   0   0   1   1             S4
+ 0   1   0   1   0   1    0    0   0   0   0                 C
                                                                  4
  1   0   1   1   0   0    0    1   0   0   1   1   Product




Figure 6.18. The multiplication example from Figure 6.17 performed using
             carry­save addition.
Manual Division
          21                                10101
    13   274                   1101     100010010
         26                              1101
         14                              10000
         13                               1101
          1                                 1110
                                            1101
                                               1


          Longhand division examples.
Longhand Division Steps
 Position the divisor appropriately with respect to the
  dividend and performs a subtraction.
 If the remainder is zero or positive, a quotient bit of 1
  is determined, the remainder is extended by another
  bit of the dividend, the divisor is repositioned, and
  another subtraction is performed.
 If the remainder is negative, a quotient bit of 0 is
  determined, the dividend is restored by adding back
  the divisor, and the divisor is repositioned for another
  subtraction.
Circuit Arrangement
                                                                          Shift left

      an      an­1                         a0                 qn­1                        q0
                                                                        Dividend Q
                                     A                                          Quotient
                                                                                 Setting



   N+1 bit                                       Add/Subtract
    adder
                                                                                        Control
                                                                                       Sequencer


              0      mn­1                        m0

                            Divisor M


                      Figure 6.21. Circuit arrangement for binary division.
Binary Division
        Hardware Implementation
Restoring Division
 Shift A and Q left one binary position
 Subtract M from A, and place the answer back in A
 If the sign of A is 1, set q0 to 0 and add M back to A
  (restore A); otherwise, set q0 to 1
 Repeat these steps n times
Examples         Initially 0

                 Shift
                           0
                           0
                               0
                               0
                               0
                                   0
                                   0
                                   0
                                       0
                                       1
                                       0
                                           0
                                           1
                                           1
                                               1 0 0 0

                                               0 0 0
                  Subtract 1   1   1   0   1                   First cycle
                  Set q0 1     1   1   1   0
                  Restore              1   1
                           0   0   0   0   1   0 0 0 0
          1 0    Shift     0   0   0   1   0   0 0 0
 1 1   1 0 0 0    Subtract 1   1   1   0   1
         1 1      Set q0 1     1   1   1   1                   Second cycle
                  Restore              1   1
          1 0              0   0   0   1   0   0 0 0 0
                 Shift     0   0   1   0   0   0 0 0
                  Subtract 1   1   1   0   1
                  Set q0 0     0   0   0   1                  Third cycle

                 Shift    0 0 0 1          0   0 0 0 1
                 Subtract 1 1 1 0          1   0 0 1
                 Set q0 1 1 1 1            1                   Fourth cycle
                 Restore        1          1
                          0 0 0 1          0   0 0 1 0

                               Remainder        Quotient



                         Figure 6.22. A restoring­division example.
Restoring Division
Flow Chart
Nonrestoring Division
 Avoid the need for restoring A after an
  unsuccessful subtraction.
 Any idea?
 Step 1: (Repeat n times)
 If the sign of A is 0, shift A and Q left one bit position and
  subtract M from A; otherwise, shift A and Q left and add M
  to A.
 Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.
 Step2: If the sign of A is 1, add M to A
Examples                       Initially

                                Shift
                                            0
                                            0
                                            0
                                                0
                                                0
                                                0
                                                    0
                                                    0
                                                    0
                                                        0
                                                        1
                                                        0
                                                            0
                                                            1
                                                            1
                                                                1 0 0 0

                                                                0 0 0       First cycle
                                Subtract    1   1   1   0   1
                                Set q 0     1   1   1   1   0   0 0 0 0

                                Shift       1 1 1 0 0           0 0 0
                                Add         0 0 0 1 1                         Second cycle

                                Set q       1 1 1 1 1           0 0 0 0
                                        0

                                Shift       1 1 1 1 0           0 0 0
    1 1 1 1 1                   Add         0 0 0 1 1                       Third cycle
                   Restore
    0 0 0 1 1                   Set q       0 0 0 0 1           0 0 0 1
                  remainder             0
Add 0 0 0 1 0
     Remainder                  Shift       0 0 0 1 0           0 0 1
                                Subtract    1 1 1 0 1                       Fourth cycle
                                Set q       1 1 1 1 1           0 0 1 0
                                      0

                                                                 Quotient
                         A nonrestoring­division example.
Nonrestoring Division
Flow Chart
If b is a binary vector, then we have seen that it can be interpreted as
 an unsigned integer by:
               V(b) = b31.231 + b30.230 + bn-3.229 + .... + b1.21 + b0.20

This vector has an implicit binary point to its immediate right:
               b31b30b29....................b1b0.      implicit binary point

Suppose if the binary vector is interpreted with the implicit binary point is
just left of the sign bit:
             implicit binary point                  .b31b30b29....................b1b0

 The value of b is then given by:

              V(b) = b31.2-1 + b30.2-2 + b29.2-3 + .... + b1.2-31 + b0.2-32
The value of the unsigned binary fraction is:
             V(b) = b31.2-1 + b30.2-2 + b29.2-3 + .... + b1.2-31 + b0.2-32

The range of the numbers represented in this format is:

                   0 ≤ V (b) ≤ 1 − 2 −32 ≈ 0.9999999998

In general for a n-bit binary fraction (a number with an assumed binary
point at the immediate left of the vector), then the range of values is:


                                 0 ≤ V (b) ≤ 1 − 2 − n
•Previous representations have a fixed point. Either the point is to the immediate
right or it is to the immediate left. This is called Fixed point representation.
•Fixed point representation suffers from a drawback that the representation can
only represent a finite range (and quite small) range of numbers.


A more convenient representation is the scientific representation, where
the numbers are represented in the form:

                         x = m1 .m2 m3 m4 × b ±e
Components of these numbers are:

                  Mantissa (m), implied base (b), and exponent (e)
A number such as the following is said to have 7 significant digits
                         x = ±0.m1m2m3m4m5m6m7 × b ±e

Fractions in the range 0.0 to 0.9999999 need about 24 bits of precision
(in binary). For example the binary fraction with 24 1’s:
                   111111111111111111111111 = 0.9999999404


Not every real number between 0 and 0.9999999404 can be represented
by a 24-bit fractional number.
The smallest non-zero number that can be represented is:

                   000000000000000000000001 = 5.96046 x 10-8


Every other non-zero number is constructed in increments of this value.
•In a 32-bit number, suppose we allocate 24 bits to represent a fractional
mantissa.
•Assume that the mantissa is represented in sign and magnitude format,
and we have allocated one bit to represent the sign.
•We allocate 7 bits to represent the exponent, and assume that the
exponent is represented as a 2’s complement integer.
•There are no bits allocated to represent the base, we assume that the
base is implied for now, that is the base is 2.
•Since a 7-bit 2’s complement number can represent values in the range
-64 to 63, the range of numbers that can be represented is:

                   0.0000001 x 2-64     < = | x | <= 0.9999999 x 263

•In decimal representation this range is:

                       0.5421 x 10-20    < = | x | <= 9.2237 x 1018
1          7                                    24




   Sign       Exponent                                Fractional mantissa
   bit
•24-bit mantissa with an implied binary point to the immediate left
•7-bit exponent in 2’s complement form, and implied base is 2.
Consider the number:        x = 0.0004056781 x 1012

If the number is to be represented using only 7 significant mantissa digits,
 the representation ignoring rounding is:        x = 0.0004056 x 1012

If the number is shifted so that as many significant digits are brought into
7 available slots:
                      x = 0.4056781 x 109 = 0.0004056 x 1012

Exponent of x was decreased by 1 for every left shift of x.
A number which is brought into a form so that all of the available mantissa
digits are optimally used (this is different from all occupied which may
not hold), is called a normalized number.

Same methodology holds in the case of binary mantissas

                 0001101000(10110) x 28 = 1101000101(10) x 25
•A floating point number is in normalized form if the most significant
1 in the mantissa is in the most significant bit of the mantissa.
•All normalized floating point numbers in this system will be of the form:

                                   0.1xxxxx.......xx

 Range of numbers representable in this system, if every number must be
 normalized is:
                          0.5 x 2-64 <= | x | < 1 x 263
The procedure for normalizing a floating point number is:
                Do (until MSB of mantissa = = 1)
                    Shift the mantissa left (or right)
                    Decrement (increment) the exponent by 1
                end do

    Applying the normalization procedure to:     .000111001110....0010 x 2-62
                                        gives:   .111001110........            x 2-65

But we cannot represent an exponent of –65, in trying to normalize the
number we have underflowed our representation.
    Applying the normalization procedure to:     1.00111000............x 263
                                        gives:   0.100111..............x 264

This overflows the representation.
So far we have assumed an implied base of 2, that is our floating point
numbers are of the form:
                                x = m 2e

 If we choose an implied base of 16, then:

                                    x = m 16e

 Then:
                    y = (m.16) .16e-1 (m.24) .16e-1 = m . 16e = x


•Thus, every four left shifts of a binary mantissa results in a decrease of 1
in a base 16 exponent.
•Normalization in this case means shifting the mantissa until there is a 1 in
the first four bits of the mantissa.
•Rather than representing an exponent in 2’s complement form, it turns out to be
more beneficial to represent the exponent in excess notation.
•If 7 bits are allocated to the exponent, exponents can be represented in the range
of -64 to +63, that is:
                               -64 <= e <= 63
Exponent can also be represented using the following coding called as excess-64:

                                E’ = Etrue + 64
In general, excess-p coding is represented as:
                                E’ = Etrue + p

 True exponent of -64 is represented as 0
                0 is represented as 64
                63 is represented as 127

This enables efficient comparison of the relative sizes of two floating point numbers.
IEEE Floating Point notation is the standard representation in use. There are two
representations:
    - Single precision.
     - Double precision.
Both have an implied base of 2.
Single precision:
  - 32 bits (23-bit mantissa, 8-bit exponent in excess-127 representation)
Double precision:
  - 64 bits (52-bit mantissa, 11-bit exponent in excess-1023 representation)
Fractional mantissa, with an implied binary point at immediate left.




     Sign     Exponent                           Mantissa
     1          8 or 11                         23 or 52
•Floating point numbers have to be represented in a normalized form to
maximize the use of available mantissa digits.
•In a base-2 representation, this implies that the MSB of the mantissa is
always equal to 1.
•If every number is normalized, then the MSB of the mantissa is always 1.
We can do away without storing the MSB.
•IEEE notation assumes that all numbers are normalized so that the MSB
of the mantissa is a 1 and does not store this bit.
•So the real MSB of a number in the IEEE notation is either a 0 or a 1.
•The values of the numbers represented in the IEEE single precision
notation are of the form:
                              (+,-) 1.M x 2(E - 127)
•The hidden 1 forms the integer part of the mantissa.
•Note that excess-127 and excess-1023 (not excess-128 or excess-1024) are used
to represent the exponent.
In the IEEE representation, the exponent is in excess-127 (excess-1023)
notation.
The actual exponents represented are:

                     -126 <= E <= 127 and -1022 <= E <= 1023
                     not
                     -127 <= E <= 128 and -1023 <= E <= 1024


This is because the IEEE uses the exponents -127 and 128 (and -1023 and
1024), that is the actual values 0 and 255 to represent special conditions:
      - Exact zero
      - Infinity
Addition:
       3.1415 x 108 + 1.19 x 106 = 3.1415 x 108 + 0.0119 x 108 = 3.1534 x 108
Multiplication:
              3.1415 x 108 x 1.19 x 106 = (3.1415 x 1.19 ) x 10(8+6)

Division:
             3.1415 x 108 / 1.19 x 106 = (3.1415 / 1.19 ) x 10(8-6)

Biased exponent problem:
If a true exponent e is represented in excess-p notation, that is as e+p.
Then consider what happens under multiplication:

            a. 10(x + p) * b. 10(y + p) = (a.b). 10(x + p + y +p) = (a.b). 10(x +y + 2p)

Representing the result in excess-p notation implies that the exponent
should be x+y+p. Instead it is x+y+2p.
Biases should be handled in floating point arithmetic.
Floating point arithmetic: ADD/SUB
rule
 Choose the number with the smaller exponent.
 Shift its mantissa right until the exponents of both the
  numbers are equal.
 Add or subtract the mantissas.
 Determine the sign of the result.
 Normalize the result if necessary and truncate/round
  to the number of mantissa bits.

  Note: This does not consider the possibility of overflow/underflow.
Floating point arithmetic: MUL rule
 Add the exponents.
 Subtract the bias.
 Multiply the mantissas and determine the sign of the
  result.
 Normalize the result (if necessary).
 Truncate/round the mantissa of the result.
Floating point arithmetic: DIV rule
 Subtract the exponents
 Add the bias.
 Divide the mantissas and determine the sign of the
  result.
 Normalize the result if necessary.
 Truncate/round the mantissa of the result.


  Note: Multiplication and division does not require alignment of the
  mantissas the way addition and subtraction does.
While adding two floating point numbers with 24-bit mantissas, we shift
the mantissa of the number with the smaller exponent to the right until
the two exponents are equalized.
This implies that mantissa bits may be lost during the right shift (that is,
bits of precision may be shifted out of the mantissa being shifted).
To prevent this, floating point operations are implemented by keeping
guard bits, that is, extra bits of precision at the least significant end
of the mantissa.
The arithmetic on the mantissas is performed with these extra bits of
precision.
After an arithmetic operation, the guarded mantissas are:
   - Normalized (if necessary)
   - Converted back by a process called truncation/rounding to a 24-bit
     mantissa.
Truncation/rounding
 Straight chopping:
   The guard bits (excess bits of precision) are dropped.

 Von Neumann rounding:
   If the guard bits are all 0, they are dropped.
   However, if any bit of the guard bit is a 1, then the LSB of the retained bit is
    set to 1.
 Rounding:
   If there is a 1 in the MSB of the guard bit then a 1 is added to the LSB of the
    retained bits.
Rounding
 Rounding is evidently the most accurate truncation
  method.
 However,
   Rounding requires an addition operation.
   Rounding may require a renormalization, if the addition operation de-
    normalizes the truncated number.

          0.111111100000 rounds to 0.111111 + 0.000001
          =1.000000 which must be renormalized to 0.100000

 IEEE uses the rounding method.

More Related Content

What's hot

Making Of 0-9 Decade Counter with 7 segment display
Making Of 0-9 Decade Counter with 7 segment displayMaking Of 0-9 Decade Counter with 7 segment display
Making Of 0-9 Decade Counter with 7 segment displayOmkar Rane
 
Associative memory 14208
Associative memory 14208Associative memory 14208
Associative memory 14208Ameer Mehmood
 
Parallel Processors (SIMD)
Parallel Processors (SIMD) Parallel Processors (SIMD)
Parallel Processors (SIMD) Ali Raza
 
Pdh and sdh1
Pdh and sdh1Pdh and sdh1
Pdh and sdh1Khant Oo
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transferlavanya marichamy
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architectureZakaria Gomaa
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorDarling Jemima
 
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...IAEME Publication
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set Nitin Ahire
 
Project Report Of SRAM Design
Project Report Of SRAM DesignProject Report Of SRAM Design
Project Report Of SRAM DesignAalay Kapadia
 
Os rtos.ppt
Os rtos.pptOs rtos.ppt
Os rtos.pptrahul km
 
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly LanguageChapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly Languagecmkandemir
 

What's hot (20)

Verilog Pli
Verilog PliVerilog Pli
Verilog Pli
 
VHDL course
VHDL courseVHDL course
VHDL course
 
Making Of 0-9 Decade Counter with 7 segment display
Making Of 0-9 Decade Counter with 7 segment displayMaking Of 0-9 Decade Counter with 7 segment display
Making Of 0-9 Decade Counter with 7 segment display
 
Associative memory 14208
Associative memory 14208Associative memory 14208
Associative memory 14208
 
Parallel Processors (SIMD)
Parallel Processors (SIMD) Parallel Processors (SIMD)
Parallel Processors (SIMD)
 
Pdh and sdh1
Pdh and sdh1Pdh and sdh1
Pdh and sdh1
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architecture
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM Processor
 
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
 
ARM
ARMARM
ARM
 
8051 micro controllers Instruction set
8051 micro controllers Instruction set 8051 micro controllers Instruction set
8051 micro controllers Instruction set
 
Project Report Of SRAM Design
Project Report Of SRAM DesignProject Report Of SRAM Design
Project Report Of SRAM Design
 
Os rtos.ppt
Os rtos.pptOs rtos.ppt
Os rtos.ppt
 
Blackfin core architecture
Blackfin core architectureBlackfin core architecture
Blackfin core architecture
 
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly LanguageChapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
 
Lpc1768
Lpc1768Lpc1768
Lpc1768
 
Regular buffer v/s Clock buffer
Regular buffer v/s Clock bufferRegular buffer v/s Clock buffer
Regular buffer v/s Clock buffer
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 

Similar to Unit 2 arithmetics

Half adder and full adder
Half adder and full adderHalf adder and full adder
Half adder and full adderKamil Hussain
 
Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_rofldork
 
MCS 012 computer organisation and assembly language programming assignment…
MCS 012 computer organisation and assembly language programming assignment…MCS 012 computer organisation and assembly language programming assignment…
MCS 012 computer organisation and assembly language programming assignment…Dr. Loganathan R
 
Mux decod pld2_vs2
Mux decod pld2_vs2Mux decod pld2_vs2
Mux decod pld2_vs2WanNurdiana
 

Similar to Unit 2 arithmetics (7)

Half adder and full adder
Half adder and full adderHalf adder and full adder
Half adder and full adder
 
Section 1
Section 1Section 1
Section 1
 
Section 1
Section 1Section 1
Section 1
 
16%20 lecture
16%20 lecture16%20 lecture
16%20 lecture
 
Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_Dateof birthdesignproblem 1_
Dateof birthdesignproblem 1_
 
MCS 012 computer organisation and assembly language programming assignment…
MCS 012 computer organisation and assembly language programming assignment…MCS 012 computer organisation and assembly language programming assignment…
MCS 012 computer organisation and assembly language programming assignment…
 
Mux decod pld2_vs2
Mux decod pld2_vs2Mux decod pld2_vs2
Mux decod pld2_vs2
 

More from chidabdu

Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffmanchidabdu
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphschidabdu
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamicchidabdu
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashingchidabdu
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsortschidabdu
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heapschidabdu
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bstchidabdu
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquerchidabdu
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquerchidabdu
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforcechidabdu
 
Sienna 2 analysis
Sienna 2 analysisSienna 2 analysis
Sienna 2 analysischidabdu
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 introchidabdu
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitationschidabdu
 
Unit 3 basic processing unit
Unit 3   basic processing unitUnit 3   basic processing unit
Unit 3 basic processing unitchidabdu
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organizationchidabdu
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11chidabdu
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10chidabdu
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9chidabdu
 
Algorithm chapter 8
Algorithm chapter 8Algorithm chapter 8
Algorithm chapter 8chidabdu
 

More from chidabdu (20)

Sienna 12 huffman
Sienna 12 huffmanSienna 12 huffman
Sienna 12 huffman
 
Sienna 11 graphs
Sienna 11 graphsSienna 11 graphs
Sienna 11 graphs
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamic
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
 
Sienna 8 countingsorts
Sienna 8 countingsortsSienna 8 countingsorts
Sienna 8 countingsorts
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heaps
 
Sienna 6 bst
Sienna 6 bstSienna 6 bst
Sienna 6 bst
 
Sienna 5 decreaseandconquer
Sienna 5 decreaseandconquerSienna 5 decreaseandconquer
Sienna 5 decreaseandconquer
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
 
Sienna 3 bruteforce
Sienna 3 bruteforceSienna 3 bruteforce
Sienna 3 bruteforce
 
Sienna 2 analysis
Sienna 2 analysisSienna 2 analysis
Sienna 2 analysis
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitations
 
Unit 3 basic processing unit
Unit 3   basic processing unitUnit 3   basic processing unit
Unit 3 basic processing unit
 
Unit 5 I/O organization
Unit 5   I/O organizationUnit 5   I/O organization
Unit 5 I/O organization
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Algorithm chapter 8
Algorithm chapter 8Algorithm chapter 8
Algorithm chapter 8
 

Recently uploaded

Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 

Recently uploaded (20)

Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 

Unit 2 arithmetics

  • 2. xi yi Carry­in ci Sum s i Carry­out c i+1 At the ith stage: 0 0 0 0 0 Input: 0 0 1 1 0 ci is the carry-in 0 1 0 1 0 0 1 1 0 1 Output: 1 0 0 1 0 si is the sum 1 0 1 0 1 1 1 0 0 1 ci+1 carry-out to (i+1)st 1 1 1 1 1 state si   = xi yi ci + xi yi ci + xi yi ci + xi yi ci = x i ⊕ yi ⊕ ci ci +1 = yi c i + x i ci + x i y i Example: X 7 0 1 1 1 Carry­out xi Carry­in + Y = + 6 = +00 1 1 1 1 0 0 0 yi ci+1 ci Z 13 1 1 0 1 si Legend for stage i
  • 3. Sum Carry yi c i xi xi yi si c c i +1 i ci x xi yi i yi ci + 1 Full adder ci (FA) s i Full Adder (FA): Symbol for the complete circuit for a single stage of addition.
  • 4. •Cascade n full adder (FA) blocks to form a n-bit adder. •Carries propagate or ripple through this cascade, n-bit ripple carry adder. xn ­ 1 yn­ 1 x1 y1 x0 y0 cn ­ 1 c1 cn FA FA FA c0 sn ­ 1 s1 s0 Most significant bit Least significant bit (MSB) position (LSB) position Carry-in c0 into the LSB position provides a convenient way to perform subtraction.
  • 5. K n-bit numbers can be added by cascading k n-bit adders. xk n ­ 1 yk n ­ 1 x2n ­ 1 y2n ­ 1 xn y n xn ­ 1 y n ­ 1 x 0 y 0 cn n­bit n­bit n­bit c c kn 0 adder adder adder s s( s s s s kn ­ 1 k ­ 1) n 2n ­ 1 n n­ 1 0 Each n-bit adder forms a block, so this is cascading of blocks. Carries ripple or propagate through blocks, Blocked Ripple Carry Adder
  • 6. •Recall X – Y is equivalent to adding 2’s complement of Y to X. •2’s complement is equivalent to 1’s complement + 1. •X – Y = X + Y + 1 •2’s complement of positive and negative numbers is computed similarly. xn ­ 1 yn­ 1 x1 y1 x0 y0 cn ­ 1 c1 cn FA FA FA 1 sn ­ 1 s1 s0 Most significant bit Least significant bit (MSB) position (LSB) position
  • 7. y y y n­ 1 1 0 Add/Sub control x x x n­ 1 1 0 c n­bit adder n c 0 s s s n­ 1 1 0 •Add/sub control = 0, addition. •Add/sub control = 1, subtraction.
  • 8. Detecting overflows  Overflows can only occur when the sign of the two operands is the same.  Overflow occurs if the sign of the result is different from the sign of the operands.  Recall that the MSB represents the sign.  xn-1, yn-1, sn-1 represent the sign of operand x, operand y and result s respectively.  Circuit to detect overflow can be implemented by the following logic expressions: Overflow = xn −1 yn −1sn −1 + xn −1 yn −1sn −1 Overflow = cn ⊕ cn −1
  • 9. x0 y0 Consider 0th stage: •c1 is available after 2 gate delays. •s1 is available after 1 gate delay. c1 FA c0 s0 Sum Carry yi c i xi xi yi si c c i +1 i ci x i yi
  • 10. Cascade of 4 Full Adders, or a 4-bit adder x0 y0 x0 y0 x0 y0 x0 y0 FA FA FA FA c0 c4 c3 c2 c1 s3 s2 s1 s0 •s0 available after 1 gate delays, c1 available after 2 gate delays. •s1 available after 3 gate delays, c2 available after 4 gate delays. •s2 available after 5 gate delays, c3 available after 6 gate delays. •s3 available after 7 gate delays, c4 available after 8 gate delays. For an n-bit adder, sn-1 is available after 2n-1 gate delays cn is available after 2n gate delays.
  • 11. Recall the equations: si = xi ⊕ yi ⊕ ci ci +1 = xi yi + xi ci + yi ci Second equation can be written as: ci +1 = xi yi + ( xi + yi )ci We can write: ci +1 = Gi + Pi ci where Gi = xi yi and Pi = xi + yi •Gi is called generate function and Pi is called propagate function •Gi and Pi are computed only from xi and yi and not ci, thus they can be computed in one gate delay after X and Y are applied to the inputs of an n-bit adder.
  • 12. ci +1 = Gi + Pi ci ci = Gi −1 + Pi −1ci −1 ⇒ ci+1 = Gi + Pi (Gi −1 + Pi −1ci −1 ) continuing ⇒ ci+1 = Gi + Pi (Gi −1 + Pi −1 (Gi − 2 + Pi− 2 ci −2 )) until ci+1 = Gi + PiGi −1 + Pi Pi−1 Gi −2 + .. + Pi Pi −1 ..P1G0 + Pi Pi −1 ...P0 c 0 •All carries can be obtained 3 gate delays after X, Y and c0 are applied. -One gate delay for Pi and Gi -Two gate delays in the AND-OR circuit for ci+1 •All sums can be obtained 1 gate delay after the carries are computed. •Independent of n, n-bit addition requires only 4 gate delays. •This is called Carry Lookahead adder.
  • 13. x y x y x y x y 3 3 2 2 1 1 0 0 c4 c 3 c 2 c 1 . c 4-bit carry-lookahead B cell B cell B cell B cell 0 adder s s s s 3 2 1 0 G3 P3 G2 P2 G P G P 1 1 0 0 Carry­lookahead logic xi yi . . . c i B-cell for a single stage B cell Gi P i si
  • 14. Carry lookahead adder (contd..)  Performing n-bit addition in 4 gate delays independent of n is good only theoretically because of fan-in constraints. ci+1 = Gi + PiGi −1 + Pi Pi−1 Gi −2 + .. + Pi Pi −1 ..P1G0 + P Pi −1 ...P0 c0 i  Last AND gate and OR gate require a fan-in of (n+1) for a n- bit adder.  For a 4-bit adder (n=4) fan-in of 5 is required.  Practical limit for most gates.  In order to add operands longer than 4 bits, we can cascade 4-bit Carry-Lookahead adders. Cascade of Carry-Lookahead adders is called Blocked Carry-Lookahead adder.
  • 15.
  • 16. Carry-out from a 4-bit block can be given as: c4 = G3 + P G2 + P3 P2 G1 + P3 P2 P G0 + P3 P2 P1P0 c0 3 1 Rewrite this as: P0I = P3 P2 P1 P0 G0I = G3 + P3 G2 + P3 P2 G1 + P3 P2 P1G0 Subscript I denotes the blocked carry lookahead and identifies the block. Cascade 4 4-bit adders, c16 can be expressed as: c16 = G3 + P3I G2I + P3I P2I G1I + P3I P2I P10 G0 + P3I P2I P10 P00 c0 I I
  • 17. x15­12 y15­12 x11­8 y11­8 x7­4 y7­4 x3­0 y3­0 c16 4­bit adder c12 4­bit adder c8 4­bit adder c4 4­bit adder . c0 s15­12 s11­8 s7­4 s3­0 G3 I P3 I G2 I P 2I G 1I P 1I G 0I P0 I Carry­lookahead logic After xi, yi and c0 are applied as inputs: - Gi and Pi for each stage are available after 1 gate delay. - PI is available after 2 and GI after 3 gate delays. - All carries are available after 5 gate delays. - c16 is available after 5 gate delays. - s15 which depends on c12 is available after 8 (5+3)gate delays (Recall that for a 4-bit carry lookahead adder, the last sum bit is available 3 gate delays after all inputs are available)
  • 18.
  • 19. Product of 2 n-bit numbers is at most a 2n-bit number. Unsigned multiplication can be viewed as addition of shifted versions of the multiplicand.
  • 20. Multiplication of unsigned numbers (contd..)  We added the partial products at end.  Alternative would be to add the partial products at each stage.  Rules to implement multiplication are:  If the ith bit of the multiplier is 1, shift the multiplicand and add the shifted multiplicand to the current value of the partial product.  Hand over the partial product to the next stage  Value of the partial product at the start stage is 0.
  • 21. Typical multiplication cell Bit of incoming partial product (PPi) jth multiplicand bit ith multiplier bit ith multiplier bit carry out FA carry in Bit of outgoing partial product (PP(i+1))
  • 22. Combinatorial array multiplier Multiplicand 0 m3 0 m2 0 m1 0 m0 (PP0) q0 0 PP1 p0 q1 0 r lie PP2 tip p1 ul q2 M 0 PP3 p2 q3 0 , p7 p6 p5 p4 p3 Product is: p7,p6,..p0 Multiplicand is shifted by displacing it through an array of adders.
  • 23. Combinatorial array multiplier (contd..)  Combinatorial array multipliers are:  Extremely inefficient.  Have a high gate count for multiplying numbers of practical size such as 32- bit or 64-bit numbers.  Perform only one function, namely, unsigned integer product.  Improve gate efficiency by using a mixture of combinatorial array techniques and sequential techniques requiring less combinational logic.
  • 24. Sequential multiplication  Recall the rule for generating partial products:  If the ith bit of the multiplier is 1, add the appropriately shifted multiplicand to the current partial product.  Multiplicand has been shifted left when added to the partial product.  However, adding a left-shifted multiplicand to an unshifted partial product is equivalent to adding an unshifted multiplicand to a right-shifted partial product.
  • 25. Register A  (initially 0) Shift right C a a q q n ­ 1 0 n­ 1 0 Multiplier Q Add/Noadd control n-bit Adder MUX Control sequencer 0 0 m m0 n ­ 1 Multiplicand M
  • 26. M 1   1   0   1 Initial configuration 0 0   0   0   0 1   0   1   1 C A Q 0 1   1   0   1 1   0   1   1 Add Shift First cycle 0 0   1   1   0 1   1   0   1 1 0   0   1   1 1   1   0   1 Add Shift Second cycle 0 1   0   0   1 1   1   1   0 0 1   0   0   1 1   1   1   0 No add Shift Third cycle 0 0   1   0   0 1   1   1   1 1 0   0   0   1 1   1   1   1 Add Shift Fourth cycle 0 1   0   0   0 1   1   1   1 Product
  • 27.
  • 28. Signed Multiplication  Considering 2’s-complement signed operands, what will happen to (-13)×(+11) if following the same method of unsigned multiplication? 1 0 0 1 1 ( ­ 13) 0 1 0 1 1 ( + 11) 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 Sign extension is shown in blue 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0 0 0 1 ( ­ 143) Sign extension of negative multiplicand.
  • 29. Signed Multiplication  For a negative multiplier, a straightforward solution is to form the 2’s-complement of both the multiplier and the multiplicand and proceed as in the case of a positive multiplier.  This is possible because complementation of both operands does not change the value or the sign of the product.  A technique that works equally well for both negative and positive multipliers – Booth algorithm.
  • 31. Booth Algorithm Consider in a multiplication, the multiplier is positive 0011110, how many appropriately shifted versions of the multiplicand are added in a standard procedure? 0 1 0 1 1 0 1 0 0 +1 +1 + 1+1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 0
  • 32. Booth Algorithm  Since 0011110 = 0100000 – 0000010, if we use the expression to the right, what will happen? 0 1 0 1 1 0 1 0 +1 0 0 0 ­ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2's complement of 1 1 1 1 1 1 1 0 1 0 0 1 1 the multiplicand 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 0
  • 33. Booth in the Booth scheme, -1 times the shifted multiplicand is In general, Algorithm selected when moving from 0 to 1, and +1 times the shifted multiplicand is selected when moving from 1 to 0, as the multiplier is scanned from right to left. 0 0 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0 +1 ­1 +1 0 ­ 1 0 +1 0 0 ­ 1 +1 ­ 1 + 1 0 ­ 1 0 0 Booth recoding of a multiplier.
  • 34. Booth Algorithm 0 1 1 0 1 ( + 13) 0 1 1 0 1 X1 1 0 1 0 (­ 6) 0 ­ 1 +1 ­ 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 ( ­ 78) Booth multiplication with a negative multiplier.
  • 35. Booth Algorithm Multiplier V ersion of multiplicand selected by biti Bit i Bit i ­1 0 0 0 X M 0 1 + 1 X M 1 0 − 1 X M 1 1 0 X M Booth multiplier recoding table.
  • 36. Booth Algorithm  Best case – a long string of 1’s (skipping over 1s)  Worst case – 0’s and 1’s are alternating 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 Worst­case multiplier +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 +1 ­ 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 Ordinary multiplier 0 ­1 0 0 + 1 ­ 1 +1 0 ­ 1 +1 0 0 0 ­1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 Good multiplier 0 0 0 +1 0 0 0 0 ­1 0 0 0 +1 0 0 ­1
  • 38.
  • 39. Bit-Pair Recoding of Multipliers  Bit-pair recoding halves the maximum number of summands (versions of the multiplicand). Sign extension Implied 0 to right of LSB 1 1 1 0 1 0 0 0 0 − 1 +1 − 1 0 0 −1 −2 (a)  Example of bit­pair recoding derived from Booth recoding
  • 40. Bit-Pair Recoding of Multipliers Multiplier bit­pair Multiplier bit on the right Multiplicand selected at position i i+1 i i−1 0 0 0 0 X  M 0 0 1 +1 X  M 0 1 0 +1 X  M 0 1 1 +2 X  M 1 0 0 −2 X  M 1 0 1 −1 X  M 1 1 0 −1 X  M 1 1 1 0 X  M (b) Table of multiplicand selection decisions
  • 41. Bit-Pair Recoding of Multipliers 0 1 1 0 1 0 ­ 1 +1 ­ 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 0 1 ( + 13) 0 0 0 0 0 0 × 1 1 0 1 0 (­ 6 ) 1 1 1 0 1 1 0 0 1 0 ( ­ 78 ) 0 1 1 0 1 0 ­1 ­2 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 Figure 6.15.  Multiplication requiring only n/2 summands.41
  • 42. Carry-Save Addition of Summands  CSA speeds up the addition process. P7 P6 P5 P4 P3 P2 P1 P0 42
  • 43. Carry-Save Addition of Summands(Cont.,) P7 P6 P5 P4 P3 P2 P1 P0
  • 44. Carry-Save Addition of Summands(Cont.,)  Consider the addition of many summands, we can:  Group the summands in threes and perform carry-save addition on each of these groups in parallel to generate a set of S and C vectors in one full-adder delay  Group all of the S and C vectors into threes, and perform carry-save addition on them, generating a further set of S and C vectors in one more full-adder delay  Continue with this process until there are only two vectors remaining  They can be added in a RCA or CLA to produce the desired product
  • 45. Carry-Save Addition of Summands 1 0 1 1 0 1 (45) M X 1 1 1 1 1 1 (63) Q 1 0 1 1 0 1 A 1 0 1 1 0 1 B 1 0 1 1 0 1 C 1 0 1 1 0 1 D 1 0 1 1 0 1 E 1 0 1 1 0 1 F 1 0 1 1 0 0 0 1 0 0 1 1 (2,835) Product Figure 6.17.  A multiplication example used to illustrate carry­save addition as shown in Figure 6.18.
  • 46. 1 0 1 1 0 1 M x 1 1 1 1 1 1 Q 1 0 1 1 0 1 A 1 0 1 1 0 1 B 1 0 1 1 0 1 C 1 1 0 0 0 0 1 1 S 1 0 0 1 1 1 1 0 0 C 1 1 0 1 1 0 1 D 1 0 1 1 0 1 E 1 0 1 1 0 1 F 1 1 0 0 0 0 1 1 S 2 0 0 1 1 1 1 0 0 C 2 1 1 0 0 0 0 1 1 S1 0 0 1 1 1 1 0 0 C 1 1 1 0 0 0 0 1 1 S2 1 1 0 1 0 1 0 0 0 1 1 S 3 0 0 0 0 1 0 1 1 0 0 0 C3 0 0 1 1 1 1 0 0 C2 0 1 0 1 1 1 0 1 0 0 1 1 S4 + 0 1 0 1 0 1 0 0 0 0 0 C 4 1 0 1 1 0 0 0 1 0 0 1 1 Product Figure 6.18. The multiplication example from Figure 6.17 performed using carry­save addition.
  • 47.
  • 48. Manual Division 21 10101 13 274   1101 100010010 26 1101 14 10000 13 1101 1 1110 1101 1  Longhand division examples.
  • 49. Longhand Division Steps  Position the divisor appropriately with respect to the dividend and performs a subtraction.  If the remainder is zero or positive, a quotient bit of 1 is determined, the remainder is extended by another bit of the dividend, the divisor is repositioned, and another subtraction is performed.  If the remainder is negative, a quotient bit of 0 is determined, the dividend is restored by adding back the divisor, and the divisor is repositioned for another subtraction.
  • 50. Circuit Arrangement Shift left an an­1 a0 qn­1 q0 Dividend Q A Quotient Setting N+1 bit  Add/Subtract adder Control Sequencer 0 mn­1 m0 Divisor M Figure 6.21. Circuit arrangement for binary division.
  • 51. Binary Division Hardware Implementation
  • 52. Restoring Division  Shift A and Q left one binary position  Subtract M from A, and place the answer back in A  If the sign of A is 1, set q0 to 0 and add M back to A (restore A); otherwise, set q0 to 1  Repeat these steps n times
  • 53. Examples Initially 0 Shift 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 Subtract 1 1 1 0 1 First cycle Set q0 1 1 1 1 0 Restore 1 1 0 0 0 0 1 0 0 0 0 1 0 Shift 0 0 0 1 0 0 0 0 1 1 1 0 0 0 Subtract 1 1 1 0 1 1 1 Set q0 1 1 1 1 1 Second cycle Restore 1 1 1 0 0 0 0 1 0 0 0 0 0 Shift 0 0 1 0 0 0 0 0 Subtract 1 1 1 0 1 Set q0 0 0 0 0 1 Third cycle Shift 0 0 0 1 0 0 0 0 1 Subtract 1 1 1 0 1 0 0 1 Set q0 1 1 1 1 1 Fourth cycle Restore 1 1 0 0 0 1 0 0 0 1 0 Remainder Quotient Figure 6.22. A restoring­division example.
  • 55. Nonrestoring Division  Avoid the need for restoring A after an unsuccessful subtraction.  Any idea?  Step 1: (Repeat n times)  If the sign of A is 0, shift A and Q left one bit position and subtract M from A; otherwise, shift A and Q left and add M to A.  Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.  Step2: If the sign of A is 1, add M to A
  • 56. Examples Initially Shift 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 First cycle Subtract 1 1 1 0 1 Set q 0 1 1 1 1 0 0 0 0 0 Shift 1 1 1 0 0 0 0 0 Add 0 0 0 1 1 Second cycle Set q 1 1 1 1 1 0 0 0 0 0 Shift 1 1 1 1 0 0 0 0 1 1 1 1 1 Add 0 0 0 1 1 Third cycle Restore 0 0 0 1 1 Set q 0 0 0 0 1 0 0 0 1  remainder 0 Add 0 0 0 1 0 Remainder Shift 0 0 0 1 0 0 0 1 Subtract 1 1 1 0 1 Fourth cycle Set q 1 1 1 1 1 0 0 1 0 0 Quotient  A nonrestoring­division example.
  • 58.
  • 59. If b is a binary vector, then we have seen that it can be interpreted as an unsigned integer by: V(b) = b31.231 + b30.230 + bn-3.229 + .... + b1.21 + b0.20 This vector has an implicit binary point to its immediate right: b31b30b29....................b1b0. implicit binary point Suppose if the binary vector is interpreted with the implicit binary point is just left of the sign bit: implicit binary point .b31b30b29....................b1b0 The value of b is then given by: V(b) = b31.2-1 + b30.2-2 + b29.2-3 + .... + b1.2-31 + b0.2-32
  • 60. The value of the unsigned binary fraction is: V(b) = b31.2-1 + b30.2-2 + b29.2-3 + .... + b1.2-31 + b0.2-32 The range of the numbers represented in this format is: 0 ≤ V (b) ≤ 1 − 2 −32 ≈ 0.9999999998 In general for a n-bit binary fraction (a number with an assumed binary point at the immediate left of the vector), then the range of values is: 0 ≤ V (b) ≤ 1 − 2 − n
  • 61. •Previous representations have a fixed point. Either the point is to the immediate right or it is to the immediate left. This is called Fixed point representation. •Fixed point representation suffers from a drawback that the representation can only represent a finite range (and quite small) range of numbers. A more convenient representation is the scientific representation, where the numbers are represented in the form: x = m1 .m2 m3 m4 × b ±e Components of these numbers are: Mantissa (m), implied base (b), and exponent (e)
  • 62. A number such as the following is said to have 7 significant digits x = ±0.m1m2m3m4m5m6m7 × b ±e Fractions in the range 0.0 to 0.9999999 need about 24 bits of precision (in binary). For example the binary fraction with 24 1’s: 111111111111111111111111 = 0.9999999404 Not every real number between 0 and 0.9999999404 can be represented by a 24-bit fractional number. The smallest non-zero number that can be represented is: 000000000000000000000001 = 5.96046 x 10-8 Every other non-zero number is constructed in increments of this value.
  • 63. •In a 32-bit number, suppose we allocate 24 bits to represent a fractional mantissa. •Assume that the mantissa is represented in sign and magnitude format, and we have allocated one bit to represent the sign. •We allocate 7 bits to represent the exponent, and assume that the exponent is represented as a 2’s complement integer. •There are no bits allocated to represent the base, we assume that the base is implied for now, that is the base is 2. •Since a 7-bit 2’s complement number can represent values in the range -64 to 63, the range of numbers that can be represented is: 0.0000001 x 2-64 < = | x | <= 0.9999999 x 263 •In decimal representation this range is: 0.5421 x 10-20 < = | x | <= 9.2237 x 1018
  • 64. 1 7 24 Sign Exponent Fractional mantissa bit •24-bit mantissa with an implied binary point to the immediate left •7-bit exponent in 2’s complement form, and implied base is 2.
  • 65. Consider the number: x = 0.0004056781 x 1012 If the number is to be represented using only 7 significant mantissa digits, the representation ignoring rounding is: x = 0.0004056 x 1012 If the number is shifted so that as many significant digits are brought into 7 available slots: x = 0.4056781 x 109 = 0.0004056 x 1012 Exponent of x was decreased by 1 for every left shift of x. A number which is brought into a form so that all of the available mantissa digits are optimally used (this is different from all occupied which may not hold), is called a normalized number. Same methodology holds in the case of binary mantissas 0001101000(10110) x 28 = 1101000101(10) x 25
  • 66. •A floating point number is in normalized form if the most significant 1 in the mantissa is in the most significant bit of the mantissa. •All normalized floating point numbers in this system will be of the form: 0.1xxxxx.......xx Range of numbers representable in this system, if every number must be normalized is: 0.5 x 2-64 <= | x | < 1 x 263
  • 67. The procedure for normalizing a floating point number is: Do (until MSB of mantissa = = 1) Shift the mantissa left (or right) Decrement (increment) the exponent by 1 end do Applying the normalization procedure to: .000111001110....0010 x 2-62 gives: .111001110........ x 2-65 But we cannot represent an exponent of –65, in trying to normalize the number we have underflowed our representation. Applying the normalization procedure to: 1.00111000............x 263 gives: 0.100111..............x 264 This overflows the representation.
  • 68. So far we have assumed an implied base of 2, that is our floating point numbers are of the form: x = m 2e If we choose an implied base of 16, then: x = m 16e Then: y = (m.16) .16e-1 (m.24) .16e-1 = m . 16e = x •Thus, every four left shifts of a binary mantissa results in a decrease of 1 in a base 16 exponent. •Normalization in this case means shifting the mantissa until there is a 1 in the first four bits of the mantissa.
  • 69. •Rather than representing an exponent in 2’s complement form, it turns out to be more beneficial to represent the exponent in excess notation. •If 7 bits are allocated to the exponent, exponents can be represented in the range of -64 to +63, that is: -64 <= e <= 63 Exponent can also be represented using the following coding called as excess-64: E’ = Etrue + 64 In general, excess-p coding is represented as: E’ = Etrue + p True exponent of -64 is represented as 0 0 is represented as 64 63 is represented as 127 This enables efficient comparison of the relative sizes of two floating point numbers.
  • 70. IEEE Floating Point notation is the standard representation in use. There are two representations: - Single precision. - Double precision. Both have an implied base of 2. Single precision: - 32 bits (23-bit mantissa, 8-bit exponent in excess-127 representation) Double precision: - 64 bits (52-bit mantissa, 11-bit exponent in excess-1023 representation) Fractional mantissa, with an implied binary point at immediate left. Sign Exponent Mantissa 1 8 or 11 23 or 52
  • 71. •Floating point numbers have to be represented in a normalized form to maximize the use of available mantissa digits. •In a base-2 representation, this implies that the MSB of the mantissa is always equal to 1. •If every number is normalized, then the MSB of the mantissa is always 1. We can do away without storing the MSB. •IEEE notation assumes that all numbers are normalized so that the MSB of the mantissa is a 1 and does not store this bit. •So the real MSB of a number in the IEEE notation is either a 0 or a 1. •The values of the numbers represented in the IEEE single precision notation are of the form: (+,-) 1.M x 2(E - 127) •The hidden 1 forms the integer part of the mantissa. •Note that excess-127 and excess-1023 (not excess-128 or excess-1024) are used to represent the exponent.
  • 72. In the IEEE representation, the exponent is in excess-127 (excess-1023) notation. The actual exponents represented are: -126 <= E <= 127 and -1022 <= E <= 1023 not -127 <= E <= 128 and -1023 <= E <= 1024 This is because the IEEE uses the exponents -127 and 128 (and -1023 and 1024), that is the actual values 0 and 255 to represent special conditions: - Exact zero - Infinity
  • 73. Addition: 3.1415 x 108 + 1.19 x 106 = 3.1415 x 108 + 0.0119 x 108 = 3.1534 x 108 Multiplication: 3.1415 x 108 x 1.19 x 106 = (3.1415 x 1.19 ) x 10(8+6) Division: 3.1415 x 108 / 1.19 x 106 = (3.1415 / 1.19 ) x 10(8-6) Biased exponent problem: If a true exponent e is represented in excess-p notation, that is as e+p. Then consider what happens under multiplication: a. 10(x + p) * b. 10(y + p) = (a.b). 10(x + p + y +p) = (a.b). 10(x +y + 2p) Representing the result in excess-p notation implies that the exponent should be x+y+p. Instead it is x+y+2p. Biases should be handled in floating point arithmetic.
  • 74. Floating point arithmetic: ADD/SUB rule  Choose the number with the smaller exponent.  Shift its mantissa right until the exponents of both the numbers are equal.  Add or subtract the mantissas.  Determine the sign of the result.  Normalize the result if necessary and truncate/round to the number of mantissa bits. Note: This does not consider the possibility of overflow/underflow.
  • 75. Floating point arithmetic: MUL rule  Add the exponents.  Subtract the bias.  Multiply the mantissas and determine the sign of the result.  Normalize the result (if necessary).  Truncate/round the mantissa of the result.
  • 76. Floating point arithmetic: DIV rule  Subtract the exponents  Add the bias.  Divide the mantissas and determine the sign of the result.  Normalize the result if necessary.  Truncate/round the mantissa of the result. Note: Multiplication and division does not require alignment of the mantissas the way addition and subtraction does.
  • 77. While adding two floating point numbers with 24-bit mantissas, we shift the mantissa of the number with the smaller exponent to the right until the two exponents are equalized. This implies that mantissa bits may be lost during the right shift (that is, bits of precision may be shifted out of the mantissa being shifted). To prevent this, floating point operations are implemented by keeping guard bits, that is, extra bits of precision at the least significant end of the mantissa. The arithmetic on the mantissas is performed with these extra bits of precision. After an arithmetic operation, the guarded mantissas are: - Normalized (if necessary) - Converted back by a process called truncation/rounding to a 24-bit mantissa.
  • 78. Truncation/rounding  Straight chopping:  The guard bits (excess bits of precision) are dropped.  Von Neumann rounding:  If the guard bits are all 0, they are dropped.  However, if any bit of the guard bit is a 1, then the LSB of the retained bit is set to 1.  Rounding:  If there is a 1 in the MSB of the guard bit then a 1 is added to the LSB of the retained bits.
  • 79. Rounding  Rounding is evidently the most accurate truncation method.  However,  Rounding requires an addition operation.  Rounding may require a renormalization, if the addition operation de- normalizes the truncated number. 0.111111100000 rounds to 0.111111 + 0.000001 =1.000000 which must be renormalized to 0.100000  IEEE uses the rounding method.