half adder & full adder patrick marshall. intro adding binary digits half adder full adder...

19
Half Adder & Full Adder Patrick Marshall

Upload: christine-burke

Post on 13-Dec-2015

232 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Half Adder & Full Adder

Patrick Marshall

Page 2: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Intro

• Adding binary digits

• Half adder

• Full adder

• Parallel adder (ripple carry)

• Arithmetic overflow

Page 3: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Adding Binary Numbers

10110 - 2200110 - 611100 - 28

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 10

A key requirement of digital computers is the ability to use logical functions to perform arithmetic operations. How do we add two binary numbers? Let's start by adding two binary bits. Since each bit has only two possible values, 0 or 1, there are only four possible combinations of inputs. These four possibilities, and the resulting sums, are:

Page 4: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Truth table for 2 bit binary addition

Inputs Outputs

A B Carry Sum

0

0

1

1

0

1

0

1

0

0

0

1

0

1

1

0

Carry = A.B Sum = A.B + A.B

Page 5: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

One possible implementation

• Note: The Half adder is sometimes drawn using a XOR gate to derive the sum. This is a common alternative to the circuit above which performs the same logic

Page 6: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Half adder

HA

A B

Cout S

It would be tedious to draw the full implementation of the half adder each time it appeared in a more complex circuit, so we commonly draw it as a box, showing the inputs and the outputs.

Page 7: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Adding groups of digits

In digital circuits we usually have to add groups of bits together, rather than simply one bit to one bit as shown in the half adder. If multiple bit number representations, like 100110 are to be added to 00110 for each digit additions we must take into account carry bits from previous steps of the process. In other words we need a circuit which will do the full job of multiple bit binary addition. The half adder is so called because it performs ‘half’ the job of binary addition.

10110 = 22 decimal

00110 = 6 decimal

11100 = 28 decimal

0 + 0 + 0 = 0

1 + 0 + 0 = 1

1 + 1 + 0 = 10

1 + 1 + 1 = 11

Page 8: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Full adder using half AddersCin

HA

A B

HA

S2Cout

We can implement a full adder circuit using two half adders. Inputs A and B are added together using the first HA, with the resultant Sum bit been added with the Carry in (from previous bit additions) using the second HA. The sum bit of this second adder is the true sum with the true carry been generated if either of the half adder stages generated a carry

C1 S1

C2

Page 9: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Implementing the Full adder circuit

A B Cin SumCout

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

This adder can be considered a three input adder. Two inputs, A&B, from the bits of the numbers we are adding and one bit, Cin, is from additions of previous bits

Sum = ABC + ABC + ABC + ABC

Cout = ABC + ABC + ABC +ABC

Page 10: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Full adder

• Cout = ABC + ABC + ABC +ABC

Cout = AB + AC + BC

AB

C

00 01 11 10

0 1

1 1 1 1

Page 11: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Full adder circuits

Page 12: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Full adder shorthand

FA

A B Cin

Cout S

There are many other ways to implement a Full adder circuit, using Nor gates only, using Nand gates only, using Xor gates. In many cases the implementation details are unimportant, so we can use the shorthand representation shown to the left. The important thing to note is that the full adder has three inputs (A B and Carry in) and two outputs (Carry out and Sum)

Page 13: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Adding mulitple bits

• We have seen how to add two binary digits using the half adder, we have seen how to add add two binary digits and a carry digit from a previous stage using the full adder. These operations are not terribly useful as generally we need to add large numbers together which are represented by multiple binary digits.

• We will now look at a way to achieve this using a parallel full adder.

Page 14: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Parallel Full Adder

• A parrallel adder adds all the bits the binary numbers in a single operation.

• One such adder is known as the ripple carry adder

Page 15: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Ripple Carry adder

The first stage can calculate it’s Sum and Carry as soon as the input A0 and B0 are valid. The second stage must wait for the first stage to complete it’s job before it’s output is valid.Likewise the third stage must wait for the outputs of both the first and second stage to be valid. The carry bit ripples through all the stages. This is why this circuit is known as the ripple carry adder.The length of time taken to add the two numbers is proportional to the number of bits in the number.

Page 16: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Notes on Ripple Carry adder

Setting the “Carry in to 1st Stage” to a ‘1’ to generate A+B+1. If input B were zero the circuit would function as an incrementor. This also is handy when applying complimentary arithmetic.

The Carry out bit can be used to determine if arithmetic overflow has occurred.

Overflow occurs when the resulting value of an operation performed on valid representations of numbers is out of the range of valid values. That is, the resulting value is greater than max or less than min.

It is possible to reduce partially the effect of the ripple-through carry by creating what are called “carry look ahead circuits”. That is the carry out to stage 5 can be calculated by inspecting the inputs to 4, 3, 2 and 1. This high speed circuit avoids the delays experience if a ripple through carry circuit.

Page 17: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Arithmetic overflow

• Consider 4 bit two’s complement additions, so the valid decimal range is from –8 to +7

0100 = 4

+0010 = 2

0110 = 6

1100 = -4

+1110 = -2

11110 = -2

0111 = 7

+0011 = 3

1010 = -6

1000 = -8

+1100 = -4

10100 = +4

The first two sum are fine, but there’s something funny with 7 + 3 = -6 and –8 – 4 = +4

Page 18: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Arithmetic Overflow

• Overflow occurs if the result of adding two positive numbers yields a negative result or if the adding of two negative numbers result in a positive result. If the sign bits of the two numbers are the same but the sign bit of the result is different then arithmetic overflow has occurred.

Overflow (V) = A sign .B sign .Sum sign or A sign .B sign .Sum sign

Page 19: Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow

Summary

• Adding binary digits

• Half adder

• Full adder

• Parallel adder (ripple carry)

• Arithmetic overflow