Comp Arithmetic
Comp Arithmetic
Sign-Magnitude System
Magnitude and Sign is represented distinctively.
For an eight-bit signed number
• MSB represents sign of the number.
• 7-bits represent magnitude ≤ 127.
A7 A6 A5 A4 A3 A2 A1 A0
0 1 0 1 1 0 1 1
Sign Magnitude = 91
Bit (+ve)
2's Complement
(22) 10110
1'complement
Negation
Converting a +ve number to its -ve equivalent
or a -ve number to its +ve equivalent
2's complement conversion is only
needed for -ve numbers
© G.N. Khan Computer Organization & Architecture-COE608: Computer Arithmetic Page: 3
2's Complement Representation
Positive Number
Add a sign bit ‘0’ in front of the MSB
Negative Number
1. Obtain the binary representation of the
magnitude of number
2. Obtain 2's complement of the magnitude
3. Add a sign bit 1 (for -ve number) in front of the
MSB of the 2's complement obtained in step 2.
A short cut method
Begin from LSB and move left bit-by-bit towards
the MSB.
i) If the bit is 0, simply copy down the bit.
ii) Repeat step i) until the first bit of 1 is
encountered, now copy down this bit.
iii) For all subsequent bits, simply invert each
one of them.
Example: 2’s complement of – 42
For example
9 – 6 = 9 + (-6)
= 9 + (2’s complement of 6)
=
+9 0 1001
(-6) 1 1010
X
Sum = s = x • y + x • y
Y
Carry = c = x • y
A hs
S
B
Cin Cout
Carry Propagation
• Speed of a ripple adder is limited due to
carry propagation or carry ripple.
• Sum of MSB depends on the carry
generated by LSB.
Ai hsi
Si
Bi ci
Bi-1
Ai-1
Carry
B0 Lookahead
A0
Logic
C0
C1 = g0+ p0C0
C2 = g1+ p1C1 = g1+ p1g0+ p1p0C0
C3 = g2+ p2C2 = g2+ p2g1+ p2p1g0+ p2p1p0C0
C4 = COUT = g3+ p3g2+ p3p2g1+ p2p1g0+ p2p1p0C0
Carry-in from
“propagate” previous stage
a
32 ALU
result
32
b
32
a
0
1 Result
+ 2
b
CarryOut
a0 CarryIn
Result0
ALU0
b0
CarryOut
a1 CarryIn
Result1
ALU1
b1
CarryOut
a2 CarryIn
Result2
ALU2
b2
CarryOut
a31 CarryIn
Result31
ALU31
b31
a
0
1
Result
b 0 2
CarryOut
a
0
R e s u lt
b 0 2
L ess 3
C a r ry O u t
Overflow Detection
Set Overflow output to 1 when a < b
B In v e r t O p e r a t Io n
C ar ryIn
a
0
R e s u lt
b 0 2
Le ss 3
Set
O v e r f lo w
O v e rflo w
d e t e c t Io n
a0 CarryIn
b0 ALU0 Result0
Less
CarryOut
a1 CarryIn
b1 ALU1 Result1
0 Less
CarryOut
a2 CarryIn
b2 ALU2 Result2
0 Less
CarryOut
CarryIn
a0 CarryIn Result0
b0 ALU0
Less
CarryOut
a1 CarryIn Result1
b1 ALU1
0 Less
CarryOut Zero
a2 CarryIn Result2
b2 ALU2
0 Less
CarryOut
Result31
a31 CarryIn
b31 ALU31 Set
0 Less Overflow
10001111 (143)
4-bit Multiplication
A3 A2 A1 A0
B3 B2 B1 B0
A3B0 A2B0 A1B0 A0B0
A3B1 A2B1 A1B1 A0B1
A3B2 A2B2 A1B2 A0 B2
A3B3 A2 B3 A1 B3 A0 B3
S7 S6 S5 S4 S3 S2 S1 S0
A3 A2 A1 A0
B0
A3 B0 A2 B0 A1 B0 A0 B0
C C C C
S S S S
B1
A3 B1 A2 B1 A1 B1 A0 B1
C C C C
S S S S
B2
A3 B2 A2 B2 A1 B2 A0 B2
C C C C
S S S S
B3
A3 B3 A2 B3 A1 B3 A0 B3
C
S S S S
P7 P6 P5 P4 P3 P2 P1 P0
Sum In X Cin
Y
Building Block/Cell FA
A B
CO CI
S
Shift Left
Multiplicand
64 bits
Shift
Right
Multiplier
64-bit ALU
32 bits
Write
Product
Control
64 bits
Start
Multiplier(0) = 1 Multiplier(0) = 0
Test
Multiplier(0)
Yes: 32 repetitions
Done
Multiplicand
32 bits Shift
Right
Multiplier
32-bit ALU
32 bits
Shift Right
Product Control
64 bits Write
Start
Yes: 32 repetitions
Done
© G.N. Khan Computer Organization & Architecture-COE608: Computer Arithmetic Page: 34
Multiplication Process
Product Multiplier Multiplicand
0000 0000 0011 0010
dividend
1001
Check for 0 divisor
1000 1001010
Long division approach
-1000 If divisor ≤ dividend bits
divisor
10 * 1 bit in quotient, subtract
101 * Otherwise 0 bit in
1010 quotient, bring down next
-1000 dividend bit
remainder 10 Restoring division
* Subtract, and if remainder
n-bit operands yield n-bit is < 0, then add divisor back
quotient and remainder
Signed division
* Divide using absolute values
* Adjust sign of quotient and remainder as
required
mantissa exponent
1.0two x 2-1
“binary point” radix (base)
Computer arithmetic that supports it called floating
point, because it represents numbers where binary point
is not fixed, as it is for integers
• Declare such variable in C as float
S (Exponent-127)
(-1) x (1 + Significand) x 2
31 30 20 19 0
S Exponent Significand (cont’d)
S Exponent Significand
S (Exponent-127)
(-1) x (1 + Significand)x2
1 (129-127)
(-1) x (1 + .111)x2
(2)
-1 x (1.111)x2
-111.1
-7.5