Computer Arithmatic1
Computer Arithmatic1
Computer Arithmatic1
COMPUTER ARITHMETIC
Computer Arithmetic
SIGNED NUMBERS
Need to be able to represent both positive and negative numbers
- Following 3 representations
E Output Input
Parallel Adder
Carry Carry
S
As A Register Load Sum
EXAMPLE
Subtract 18 - 7 using 8-bit two’s complement arithmetic.
18 - 7 is the same as 18 + (-7), so add 18 plus negative 7.
SOLUTION:
V Complementer and
Parallel Adder
Overflow
AC
Algorithm
Subtract Add
Minuend in AC Augend in AC
Subtrahend in B Addend in B
AC AC + B’+ 1 AC AC + B
V overflow V overflow
END END
Computer Arithmetic 11
MULTIPLICATION
Computer Arithmetic 13
EXAMPLE
Multiplicand B=10111 E A Q SC
Multiplier in Q 0 00000 10011 101
Q0 = 1; add B 10111
First partial product 0 10111
Shift right EAQ 0 01011 11001 100
Q0 = 1; add B 10111
Second Partial Product 1 00010
Shift right EAQ 0 10001 01100 011
Q0 = 0; shift right EAQ 0 01000 10110 010
Q0 = 0; shift right EAQ 0 00100 01011 001
10111
Q0 = 1; add B
0 11011
Fifth partial product
0 01101 10101 000
Shift right EAQ
Final Product in AQ = 0110110101
Computer Arithmetic 15 Multiplication
Complementer and
Parallel Adder
As Qs Qn
0 E AC Q Register
EAQ
B <- Multiplicand B
Q <- MultiplierA
Algorithm
As,Qs <- Qs Bs
A <- 0, E <- 0
SC <- n-1
=0 =1
Q0
EA <- A + B
shr EAQ
=0 SC <- SC+1
END =0
Product SC
in AQ
Computer Arithmetic 16 Multiplication
BOOTH MULTIPLICATION ALGORITHM FOR SIGNED 2’S
COMPLEMENT
Multiplier
Strings of 0’s: No addition; Simply shifts
Strings of 1’s: String of 1’s from mp to mq: 2p+1 - 2q
Example
001110 (14) -> p = 3, q = 1
001110 = 23+1 - 21
M * 14 = M24 - M21
Algorithm
[1] Subtract multiplicand for the first least significant 1
in a string of 1’s in the multiplier
[2] Add multiplicand for the first 0 after the string
of 1’s in the multiplier
[3] Partial Product does not change when the
multiplier bit is identical to the previous bit
B <- Multiplicand B
Q <- Multiplier A
AC <- 0
Qn+1 <- 0
SC <- n
10 QnQn+1 01
Qn+1 : shifted out bit
? on shr of Q
11
00
AC<-AC+B’+1 AC <- AC + B
ashr(AC&Q)
SC <- SC - 1
0 SC
?
=0
END
Computer Arithmetic 19 Multiplication
B = 10111
QnQn+1 B’+1=01001 AC Q Q n+1 SC
Initial 00000 10011 0 101
10 Subtract B 01001
01001
ashr 00100 11001 1 100
11 ashr 00010 01100 1 011
01 Add B 10111
11001
ashr 11100 10110 0 010
00 ashr 11110 01011 0 001
10 Subtract B 01001
00111
ashr 00011 10101 1 000
Computer Arithmetic 20 Multiplication
ARRAY MULTIPLIER
A = a1a0: Multiplier
B = b1b0: Multiplicand b1 b0
a1 a0
C = B * A = c3c2c1c0 a0b1 a0b0
a1b1 a1b0
c3 c2 c1 c0
b1 b0
a0
b1 b0
a1
HA HA
C S C S
c3 c2 c 1 c0
Computer Arithmetic 21 Multiplication
Addend Augend
4-bit Adder
Sum and Carry Outputs
a2
b3 b2 b1 b0
Addend Augend
4-bit Adder
Sum and Carry Outputs
c6 c5 c4 c3 c2 c1 c0
Computer Arithmetic 22
Division
Computer Arithmetic 24
Example of Devision
Computer Arithmetic 25
Division
Divide Overflow
Computer Arithmetic 27 Division
SC SC-1
0 0
END SC
(Divide overflow)
END
(Quotient in Q
Remainder in R)
Computer Arithmetic 28
DIVISION
A/B=Q+R
A: Dividend; B: Divisor; Q: Quotient; R: Remainder
Divisor B = 10001, B’+ 1 = 01111
E A Q SC
Dividend: 01110 00000 5
shl EAQ 0 11100 00000
add B’+1 01111
E=1 1 01011
Set Q0=1 1 01011 00001 4
shl EAQ 0 10110 00010
Add B’+1 01111
E=1 1 00101
Set Q0=1 1 00101 00011 3
shl EAQ 0 01010 00110
add B’+1 01111
E=0; Q0=0 0 11001 00110
add B 10001
restore remainder 1 01010 2
shl EAQ 0 10100 01100
add B’+1 01111
E=1 1 00011
1 00011 01101 1
Set Q0=1 0 00110 11010
shl EAQ 01111
add B’+1 0 10101 11010
E=0; Q0=0 10001
add B 1 00110 11010 0
restore remainder
neglect E 00110
remainder in A 11010
quotient in Q
Computer Arithmetic 30 Floating Point Arithmetic
F = m x re
where m: Mantissa
r: Radix
e: Exponent
Bs B b BR
Parallel Adder
E Parallel Adder and Comparator
As A1 A a AC
Qs Q q QR
Computer Arithmetic 31
Add/Substract
Computer Arithmetic 32 Floating Point Arithmetic
0 1 1
As Bs As Bs
+ or - of
0 0 mantissa
EA<-A+B’+1 EA A+B
A A’+1 0 E
As A’s 1
0 =0
A
0 Normalization
A1 AC 0 E
shl A 1 shr A
a a+1 A1 E
a a+1
END
Computer Arithmetic 33
Multiplication
Computer Arithmetic 34 Floating Point Arithmetic
=0
BR
0
=0
QR
0
AC 0
aq
aa+b
a a - bias
Multiply mantissa
(finxed point
multiplication)
shl AQ 0 A1
aa-1
1
END
(Product is in AC)
Computer Arithmetic 35 Floating Point Arithmetic
A A+B A A+B
shr A
a a+1
a a+b’+1
a a+bias
qa
BCD ADD
BCD ADDER
If we can convert Binary Sums to BCD Sum ,
we can use a binary adder to add two BCD numbers
1 0
K Take next
higher digit
Z8 0
1
1
Z4 done
0 ?
1 0 END
Z2
BCD Carry
0
0110
4-bit Binary Adder
S8 S 4 S 2 S 1
Computer Arithmetic 39 Decimal Arithmetic
Addition