ddition and Subtraction Philipp Koehn 9 February 2018
1 addition
1-it dder 2 Let s start simple: dding two 1-it numbers Truth table + 0 0 0 0 1 1 1 0 1 1 1 10
Really 2 Operations 3 Truth table for "position 0" bit + 0 0 0 0 1 1 1 0 1 1 1 0 xor Truth table for carry bit + carry 0 0 0 0 1 0 1 0 0 1 1 1 and
Reminder: asic Gates 4 ND OR NOT NND NOR
Circuits 5 "Position 0" bit OUT0 0 0 0 0 1 1 1 0 1 1 1 0 xor OR NND ND OUT0 Carry bit OUTC 0 0 0 0 1 0 1 0 0 1 1 1 and ND OUTC
Putting them Together 6 OR ND OUT0 NND ND CRRY
N-it ddition 7 011 +11 --- 110 --- 110
N-it ddition 8 011 +11 --- 110 --- 110 1+1 = 0, carry the 1
N-it ddition 9 011 +11 --- 110 --- 110 1+1+1 = 1, carry the 1
N-it ddition 10 011 +11 --- 110 --- 110 copy carry bit
1-it dder 11 OR ND OUT0 NND ND CRRY Our adder cannot handle carry as input yet
Half 1-it dder 12 OR ND OUT0 NND ND CRRY 1-IT HLF DDER
uilding a 1-it Full dder 13 1-IT HLF DDER S C SUM CRRY
uilding a 1-it Full dder 14 CRRY 1-IT HLF DDER S C 1-IT HLF DDER CRRY S C SUM CRRY
uilding a 1-it Full dder 15 CRRY 1-IT HLF DDER S C 1-IT HLF DDER S C OR SUM CRRY
1-it Full dder 16 CRRY 1-IT HLF DDER S C 1-IT HLF DDER S C OR SUM CRRY 1-IT FULL DDER
N-it Full dder 17 011 +11 --- 110 --- 110
N-it Full dder 18 011 +11 --- 110 --- 110 0 0 1-IT FULL DDER CO CI S SUM0
N-it Full dder 19 011 +11 --- 110 --- 110 1 1 1-IT FULL DDER CO CI S 0 0 1-IT FULL DDER CO CI S SUM1 SUM0
N-it Full dder 20 2 1 0 2 1 0 and so on... 1-IT FULL DDER CI 1-IT FULL DDER CI 1-IT FULL DDER CI CO S CO S CO S SUM2 SUM1 SUM0
21 subtraction
First, a Trick 22 Normally, we subtract like this: 0253-176 ---- 0110 ---- 0077
Computing the Inverse 23 Now we use the inverse of the subtrahend 0999-176 ---- 0823
Subtraction by ddition 24 This allows us to carry our subtraction by addition Well, with minor corrections 00253 +0823 ----- 01076 01076 +0001-1000 ----- 0077
lso Works in inary 25 Original problem 00253-0176 ----- 00077 0011111101-010110000 ---------- 0001001101 Inverse of subtrahend 00823 0001001111 ddition 00253 +0823 ----- 01076 Corrections +0001-1000 ---------- 0077 0011111101 +001001111 ---------- 0101001100 +000000001-100000000 ---------- 0001001101
Start with N-it dder 26 0 CO 1 2 3 0 1 2 4-IT FULL DDER 3 CI S0 S1 S2 S3
Invert its of Subtrahend 27 0 1 2 3 0 CO 1 2 3 0 1 2 4-IT FULL DDER 3 CI S0 S1 S2 S3
dd One 28 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 CO 4-IT FULL DDER CI V S0 S1 S2 S3 Trick: add one as carry in
Invert Overflow --- DONE 29 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 CO 4-IT FULL DDER CI V S0 S1 S2 S3 OVERFLOW SUM mm...
30 unifying addition and subtraction machines
Goal 31 Not two machines for addition and subtraction Combined adder and subtractor Input:,, and subtraction flag SU Output if SU=0: + if SU=1: -
NOT only if SU 32 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 CO 4-IT FULL DDER CI V S0 S1 S2 S3 OVERFLOW SUM mm...
NOT only if SU 33 Truth table SU X OUT 0 0 0 0 1 1 1 0 1 1 1 0 Looks like XOR XOR
Combined Machine 34 0 1 2 3 0 1 2 3 SU 0 1 2 3 0 1 2 3 SU CO 4-IT FULL DDER S0 S1 S2 S3 CI SU OVERFLOW SUM