260 likes | 707 Views
Subtractors. Module M8.2 Section 6.2. Subtractors. Half Subtractor Full Subtractor Adder/Subtractor - 1 Adder/Subtractor - 2. A . 0 . D . 0 . B . 0 . C . 1 . Half Subtractor. A . B . D . C . 0 . 0 . 0 . 1 . 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0. 2. 1. 0 -1 1.
E N D
Subtractors Module M8.2 Section 6.2
Subtractors • Half Subtractor • Full Subtractor • Adder/Subtractor - 1 • Adder/Subtractor - 2
A 0 D 0 B 0 C 1 Half Subtractor A B D C 0 0 0 1 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0 2 1 0 -1 1
AiBi 00 01 11 10 Ci 0 1 Di = Ci $ (Ai $ Bi) Same as Si in full adder Full Subtractor Ci Ai Bi Di Ci+1 0 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 Di
AiBi 00 01 11 10 Ci 0 1 Full Subtractor Ci Ai Bi Di Ci+1 0 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 Ci+1 Ci+1 = !Ai & Bi # Ci & !Ai & !Bi # Ci & Ai & Bi
Full Subtractor Ci+1 = !Ai & Bi # Ci & !Ai & !Bi # Ci & Ai & Bi Ci+1 = !Ai & Bi # Ci & (!Ai & !Bi # Ai & Bi) Ci+1 = !Ai & Bi # Ci & !(Ai $ Bi) Recall: Di = Ci $ (Ai $ Bi) Ci+1 = !Ai & Bi # Ci & !(Ai $ Bi)
half subtractor half subtractor Full Subtractor Di = Ci $ (Ai $ Bi) Ci+1 = !Ai & Bi # Ci & !(Ai $ Bi)
subtract.abl MODULE subtract TITLE 'Subtractor, A. Student, 7/12/02' DECLARATIONS " INPUT PINS " A3..A0 PIN 6, 7, 11, 5; " Switch 1..4 A = [A3..A0]; " 4-bit operand B3..B0 PIN 72, 71, 66, 70; " Switch 5..8 B = [B3..B0]; " 4-bit subtrahend " OUTPUT PINS " D3..D0 PIN 39, 37, 36, 35 ISTYPE 'com'; " LED 5..8 D = [D3..D0]; " 4-bit difference BF PIN 40 ISTYPE 'com'; " LED 4; borrow flag
subtract.abl (cont’d) " INTERMEDIATE NODES " C4..C0 NODEISTYPE 'com'; " internal borrow vector Cin = [C3..C0]; Cout = [C4..C1]; EQUATIONS C0 = 0; D = C $ A $ B ; Cout = !A & B # Cin & !(A $ B); BF = C4; END subtract Di = Ci $ (Ai $ Bi) Ci+1 = !Ai & Bi # Ci & !(Ai $ Bi)
A 0 S 0 B 0 C 1 A 0 D 0 B 0 C 1 Adder/Subtractor - 1 Half subtractor Half adder E = 0: Half adder E = 1: Half subtractor
C i A D i i B i C E Adder/Subtractor-1 i+1 E = 0: Full adder E = 1: Full subtractor
C i A D i i B i C E addsub1.abl i+1 C4..C0 NODEISTYPE 'com'; " internal borrow vector Cin = [C3..C0]; Cout = [C4..C1]; EQUATIONS Cout = Cin & (E $ (A $ B)) # (E $ A) & B ;
Full Subtractor Ci Ai Bi Di Ci+1 0 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 0 0 1 1 1 1 1 Reordered Full Adder Full Adder Ci Ai Bi Si Ci+1 Ci Ai Bi Si Ci+1 1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 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 NOT
Adder/Subtractor-2 E = 0: 4-bit adder E = 1: 4-bit subtractor
+1 Add A to !B (one’s complement) plus 1 4-bit Subtractor: E = 1 That is, add A to two’s complement of B D = A - B
Question Subtract the following 4-bit binary numbers 10110110 11001011 What is the answer in hex? Was there a net borrow?