The Basics of Binary Arithmetic Operations
Explore arithmetic functions like binary addition, subtraction, overflow detection, and BCD addition using HDLs. Learn half adder, full adder, and ripple carry adder concepts.
The Basics of Binary Arithmetic Operations
E N D
Presentation Transcript
Arithmetic Functions and HDLs Chapter 4
Half adder X +Y ----- CS
Full adder X Y +Z ----- CS
Binary subtraction (for unsigned binary number) • 11100 (借位) 10011(被減數) - 1 1110(減數) --------------------------------- 10101(差) -01011(正確差)
Example • Y-X 1000011 + 0101100 ----------------- 1101 1 11 - 0010001 • X=1010100;Y=1000011 • X-Y: 1010100 +0111101(27-Y) ----------------------------- 10010001(X-Y)
Signed binary numbers Eg. -9 Sign-mag. 10001001 Sign-1’s 11110110 Sign-2’s 11110111
S0 C0 FA C1 S B A If S=0, (add) If S=1=C0, (sub)
Example • +6 00000110 +13 00001101 ------------------------------- +19 00010011 • -6 1 1 1 11010 +13 00001101 ------------------------------- +7 00000111 • +6 00000110 -13 1 1 1 10011 ------------------------------ -7 1 1 1 11001 • -6 11111010 -13 11110011 ------------------------------ -19 11101101
Overflow Overflow detection logic for addition and subtraction
B3 B2 B1 B0 A2 A1 A0 ------------------------------------------------------------ 0 A0B0 A0B2 A0B1 A0B C A1B3 A1B2 A1B1 A1B0 A2B3 A2B2 A2B1 A2B0 ------------------------------------------------------------ C6 C5 C4 C3 C2 C1 C0
BCD adder • 4 0100 +5 0101 ------------------------------------------- 9 1001 • 4 0100 +8 1000 --------------------------------------------- 12 1100 +0110 --------------------------------------------- 1 0010 (1) (2)
BCD adder • 8 1000 +9 1001 --------------------------------------------- 17 1 0001 +0110 --------------------------------------------- 1 01 11 (1) (7)
若加出來大於10 就傳出1 若收到‘1’ 則加6 (0110) S3S2S1S0