90 likes | 178 Views
CSE 140 L: Arithmetic Operators. CK Cheng. Outlines. Subtraction 1’s Complement 2’s Complement. Subtraction. Examples:. 7-5 = 2. 6-3 = 3. 00 111 101 010. 11 110 011 011. Borrow Bit. Goal: Try to utilize existing addition operator. Arithmetic: x-y-b in =d-2b out.
E N D
CSE 140 L: Arithmetic Operators CK Cheng
Outlines Subtraction 1’s Complement 2’s Complement
Subtraction Examples: 7-5 = 2 6-3 = 3 • 00 • 111 • 101 • 010 • 11 • 110 • 011 • 011 Borrow Bit
Arithmetic: x-y-bin =d-2bout From kmap: d= x y bin bout = x’y + ybin + x’bin = x’y + (x’+y)bin
Subtraction using Full Adder sum = a b cin cout = ab + (a+b)cin
One’s comp.: 2n -1 - x Two’s comp.: 2n-x, where x is a positive integer
Two’s Complement Implementation x3x2x1x0 y3y2y1y0 w3w2w1w0 z4z3 z2z1z0 0 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 0110 1100 10011 x-y = x + (2n - y) - 2n = x + (2n-1-y) +1 - 2n = x + w + 1 - 2n
One’s Complement Where 5 -2 =3 x3x2x1x0 y3y2y1y0 w3w2w1w0 0 1 0 1 0 0 1 0 1 1 0 1 x-y = x + (2n-1-y) - 2n +1 = x+w -2n+1 c4 cin Feed c4 to cin