Adder Half Full - maktabkhooneh.org · Chapter 5 A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder...

25
Chapter 5 <1> A B 0 0 0 1 1 0 1 1 S C out S = C out = Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 S C out S = C out = Full Adder C in 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 1 A B S C out C in + 1-Bit Adders

Transcript of Adder Half Full - maktabkhooneh.org · Chapter 5 A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder...

Page 1: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <1>

A B

0 0

0 1

1 0

1 1

SCout

S =

Cout

=

Half

Adder

A B

S

Cout +

A B

0 0

0 1

1 0

1 1

SCout

S =

Cout

=

Full

Adder

Cin

0 0

0 1

1 0

1 1

0

0

0

0

1

1

1

1

A B

S

Cout

Cin+

1-Bit Adders

Page 2: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <2>

A B

0 0

0 1

1 0

1 1

0

1

1

0

SCout

0

0

0

1

S =

Cout

=

Half

Adder

A B

S

Cout +

A B

0 0

0 1

1 0

1 1

0

1

1

0

SCout

0

0

0

1

S =

Cout

=

Full

Adder

Cin

0 0

0 1

1 0

1 1

0

0

0

0

1

1

1

1

1

0

0

1

0

1

1

1

A B

S

Cout

Cin+

1-Bit Adders

Page 3: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <3>

A B

0 0

0 1

1 0

1 1

0

1

1

0

SCout

0

0

0

1

S = A B

Cout

= AB

Half

Adder

A B

S

Cout +

A B

0 0

0 1

1 0

1 1

0

1

1

0

SCout

0

0

0

1

S = A B Cin

Cout

= AB + ACin

+ BCin

Full

Adder

Cin

0 0

0 1

1 0

1 1

0

0

0

0

1

1

1

1

1

0

0

1

0

1

1

1

A B

S

Cout

Cin+

1-Bit Adders

Page 4: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <4>

A B

S

Cout

Cin+

N

NN

• Types of carry propagate adders (CPAs):

– Ripple-carry (slow)

– Carry-lookahead (fast)

– Prefix (faster)

• Carry-lookahead and prefix adders faster for large adders

but require more hardware

Symbol

Multibit Adders (CPAs)

Page 5: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <5>

S31

A30

B30

S30

A1

B1

S1

A0

B0

S0

C30

C29

C1

C0

Cout ++++

A31

B31

Cin

• Chain 1-bit adders together

• Carry ripples through entire chain

• Disadvantage: slow

Ripple-Carry Adder

Page 6: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <6>

tripple = N tFA

where tFA is the delay of a full adder

Ripple-Carry Adder Delay

Page 7: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Chapter 5 <7>

Symbol Implementation

+

A B

-

YY

A B

NN

N

N N

N

N

Cout =

!Borrow

Cin=1

Subtractor

Page 8: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Adder/Subtractor

N-bit Adder Cin

N

N

N

A

N x XOR

B

sub

0: Addition1: Subtraction

Cout

Z: Output is all 0'sV: Signed Overflow

N: Output is negative

S

Page 9: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Adder/Subtractor Signed Overflow

• In signed addition, overflow occurs when: positive + positive negative

negative + negative positive

positive + negative never generates an overflow

• In signed subtraction, overflow occurs when:

positive – negative negative

negative – positive positive

positive – positive or negative – negative

never generates an overflow

Page 10: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Adder/Subtractor, Unsigned Numbers

• If A and B are unsigned numbers: sub = 0 means S = A +B

sub = 1 means S = A + ~B + 1 = A – B

• Cout is addition overflow indicator: If set, it shows 2N should be added to S

• ! Cout (= Borrow) is subtraction underflow indicator: If set, S is correctly equal to S = A – B

If not set, 2N should be deducted from S

• While Z shows output is all zero, N and V do not have any meaning in unsigned addition/subtraction

Page 11: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Adder/Subtractor, Signed Numbers

• If A and B are signed numbers: sub = 0 means S = A +B sub = 1 means S = A + ~B + 1 = A – B

• V is addition/subtraction overflow indicator • Unlike unsigned addition/subtraction, output S can

not be reconstructed when overflow occurs. • Indeed, a new addition/subtraction with extra bits

(recall sign-extension) are required to prevent any signed overflow

• While Z shows output is all zero, Cout do not have any meaning in signed addition and/or subtraction

Page 12: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Adder/Subtractor, Elaboration

• A binary adder can blindly add/subtract signed and unsigned numbers, thanks to the two’s complement signed number representation. – Warning: above statement is not correct for

multiplication and division.

• This is user responsibility to properly threat the output specially when an overflow occurs. – In unsigned numbers, Cout shows exact error amount.

– In signed numbers, output should be thrown out, when V (signed overflow) is asserted.

Page 13: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B

Page 14: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

Page 15: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B

Page 16: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B Cout

A < B ! Cout

Page 17: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B Cout

A < B ! Cout

A > B

Page 18: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Unsigned Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B Cout

A < B ! Cout

A > B Cout & ! Z

A <= B ! Cout | Z

Page 19: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B

Page 20: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

Page 21: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B

Page 22: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B (! N & ! V) | (N & V)

A < B N xor V

Page 23: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B (! N & ! V) | (N & V)

A < B N xor V

A > B

Page 24: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Signed Numbers

Calculate A + ~B + 1 (i.e. Subtract)

A == B Z

A != B ! Z

A >= B (! N & ! V) | (N & V)

A < B N xor V

A > B (N xnor V) & ! Z

A <= B (N xor V) | Z

Page 25: Adder Half Full - maktabkhooneh.org · Chapter 5  A B 0 0 0 1 1 0 1 1 C S out S = C out Half Adder A B S C out + A B 0 0 0 1 1 0 1 1 C out S S = C out Full Adder C in 0 0

Comparator, Elaboration

• For unsigned numbers, an n-bit binary adder/subtractor in subtraction mode can compare two n-bit unsigned numbers: ONLY look at Cout (= ! Borrow) and Z

• For signed numbers, above binary subtractor can compare two n-bit signed numbers, even when a signed overflow occurs and output S should be discarded: When V = 0, look at N

When V = 1, N is complemented, thus look at ! N