Download presentation

Presentation is loading. Please wait.

Published byBenjamin Derrington Modified over 2 years ago

1
Adders and Subtractors Discussion D4.1

2
Adders and Subtractors Adders Carry and Overflow Subtractors Adder-Subtractor

3
Half Adder CABS 0001 A 0 B 0 S 0 C Dec Binary

4
Multiple-bit Addition A B A 3 A 2 A 1 A A B 3 B 2 B 1 B 0 B A i +B i +C i SiSi C i+1

5
Full Adder C i A i B i S i C i CiCi AiBiAiBi SiSi

6
Full Adder C i A i B i S i C i+1 S i = C i 'A i 'B i + C i 'A i B i ' + C i A i 'B i ' + C i A i B i

7
Full Adder S i = C i '(A i 'B i + A i B i ') + C i (A i 'B i ' + A i B i ) S i = C i '(A i B i ) + C i (A i B i )' S i = C i (A i B i ) S i = C i 'A i 'B i + C i 'A i B i ' + C i A i 'B i ' + C i A i B i

8
Full Adder C i A i B i S i C i CiCi AiBiAiBi C i+1

9
Full Adder C i A i B i S i C i+1 CiCi AiBiAiBi C i+1 C i+1 = A i B i + C i B i + C i A i

10
Full Adder C i A i B i S i C i+1 CiCi AiBiAiBi C i+1 C i+1 = A i B i + C i A i 'B i + C i A i B i '

11
Full Adder C i+1 = A i B i + C i (A i 'B i + A i B i ') C i+1 = A i B i + C i (A i B i ) Recall: S i = C i (A i B i ) C i+1 = A i B i + C i (A i B i ) C i+1 = A i B i + C i A i 'B i + C i A i B i '

12
Full Adder Half-adder S i = C i (A i B i ) C i+1 = A i B i + C i (A i B i )

13
Full Adder A full adder can be made from two half adders (plus an OR gate).

14
Full Adder Block Diagram

15
4-Bit Adder C A B S

16
Full Adder Truth table CiCi AiAi BiBi SiSi C i+1 Behavior C i+1 :S i = C i + A i + B i

17
Full Adder Block Diagram

18
4-Bit Adder C :A :B C4:S

19
library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; entity adder4 is port( A : in STD_LOGIC_VECTOR(3 downto 0); B : in STD_LOGIC_VECTOR(3 downto 0); carry : out STD_LOGIC; S : out STD_LOGIC_VECTOR(3 downto 0) ); end adder4; architecture adder4 of adder4 is begin process(A,B) variable temp: STD_LOGIC_VECTOR(4 downto 0); begin temp := ('0' & A) + ('0' & B); S <= temp(3 downto 0); carry <= temp(4); end process; end adder4;

20
4-Bit Adder

21
Adders and Subtractors Adders Carry and Overflow Subtractors Adder-Subtractor

22
Carry and Overflow C = 0 V = E Dec Hex Binary Note no carry from bit 6 to bit 7 and no carry from bit 7 to C.

23
Carry and Overflow C = 0 V = B 90 Dec Hex Binary Thinking SIGNED we added two positive numbers and got a negative result. This can’t be correct! Therefore, the OVERFLOW bit, V, is set to 1. Correct answer (144) is outside the range -128 to Note carry from bit 6 to bit 7 but no carry from bit 7 to C.

24
Carry and Overflow C = 1 V = D3 108 Dec Hex Binary Thinking SIGNED we added a positive number to a negative number and got the correct positive answer. Therefore, the OVERFLOW bit, V, is cleared to 0. Correct answer (8) is inside the range -128 to Ignore carry Note carry from bit 6 to bit 7 and carry from bit 7 to C.

25
Carry and Overflow C = 1 V = E +D3 171 Dec Hex Binary Thinking SIGNED we added two negative numbers and got a positive answer. This must be wrong! Therefore, the OVERFLOW bit, V, is set to 1. Correct answer (-143) is outside the range -128 to Ignore carry Note no carry from bit 6 to bit 7 but there is a carry from bit 7 to C.

26
Overflow Note that the overflow bit was set whenever we had a carry from bit 6 to bit 7, but no carry from bit 7 to C. It was also set when we had a carry from bit 7 to C, but no carry from bit 6 to bit 7. Upshot: The overflow bit is the EXCLUSIVE-OR of a carry from bit 6 to bit 7 and a carry from bit 7 to C.

27
Adders and Subtractors Adders Carry and Overflow Subtractors Adder-Subtractor

28
Half Subtractor CABD A 0 B 0 D 0 C

29
Multiple-bit Subtraction A B A 3 A 2 A 1 A A B 3 B 2 B 1 B 0 B A i - B i - C i DiDi C i+1 1

30
Full Subtractor C i A i B i D i C i CiCi AiBiAiBi DiDi D i = C i (A i B i ) Same as S i in full adder

31
Full Subtractor C i A i B i D i C i+1 CiCi AiBiAiBi C i+1 C i+1 = A i 'B i + C i A i 'B i ' + C i A i B i

32
Full Subtractor C i+1 = A i 'B i + C i (A i 'B i ' + A i B i ) C i+1 = A i 'B i + C i (A i B i )' Recall: D i = C i (A i B i ) C i+1 = A i 'B i + C i (A i B i )' C i+1 = A i 'B i + C i A i 'B i ' + C i A i B i

33
Full Subtractor half subtractor D i = C i (A i B i ) C i+1 = A i 'B i + C i (A i B i )'

34
Adders and Subtractors Adders Carry and Overflow Subtractors Adder-Subtractor

35
C i A i B i S i C i C i A i B i S i C i+1 Full Adder Reordered Full Adder C i A i B i D i C i+1 Full Subtractor NOT

36
Making a full subtractor from a full adder

37
Adder/Subtractor E = 0: 4-bit adder E = 1: 4-bit subtractor

38
4-bit Subtractor: E = 1 +1 Add A to !B (one’s complement) plus 1 That is, add A to two’s complement of B D = A - B

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google