Professional Documents
Culture Documents
Lecture 6-Computer Arithematics-Part 2
Lecture 6-Computer Arithematics-Part 2
and Architecture
Chapter 4
Computer Arithmetic
Lecture 6
Course Content in Lectures
• Chapter 1 - Introduction
2
Division
• More complex than multiplication
• Based on long division
Division of Unsigned Binary Integers
Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
0 Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
00 Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
000 Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
0000 Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
00001 Quotient
Divisor 1011 10010011 Dividend
Division of Unsigned Binary Integers
00001 Quotient
Divisor 1011 10010011 Dividend
1011
Division of Unsigned Binary Integers
10010 = 18
1011 = 11
00001 Quotient
Divisor 1011 10010011 Dividend
1011
00111
Partial
Remainders
Division of Unsigned Binary Integers
00001 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial
Remainders
Division of Unsigned Binary Integers
000011 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial
Remainders
Division of Unsigned Binary Integers
1110 = 14
1011 = 11
000011 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
0011
Division of Unsigned Binary Integers
1110 = 14
1011 = 11
000011 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
00111
Division of Unsigned Binary Integers
0000110 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
00111
Division of Unsigned Binary Integers
0000110 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
001111
Division of Unsigned Binary Integers
00001101 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
001111
Division of Unsigned Binary Integers
1111 = 15
1011 = 11
00001101 Quotient
Divisor 1011 10010011 Dividend
1011
001110
Partial 1011
Remainders
001111
1011
100 Remainder
Flowchart for Unsigned Binary Division
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
A Q
0 0 0 0 1 1 1 0
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
A Q
0 0 0 0 1 1 1 0
0000
-0011
-------
0000
+1101
-------
1101
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
A Q
1 1 0 1 1 1 1 0
0000
-0011
-------
0000
+1101
-------
1101
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
A Q
1 1 0 1 1 1 1 0
Flowchart for Unsigned Binary Division
7
𝐸𝑥𝑎𝑚𝑝𝑙𝑒
3
M
0 0 1 1
A Q
0 0 0 0 0 1 1 1
𝑐𝑜𝑢𝑛𝑡 = 4
A Q
1 1 0 1 1 1 1 0
1101
+0011
-------
0000
A Q
0 0 0 0 1 1 1 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 3
M
0 0 1 1
A Q
0 0 0 0 1 1 1 0
A Q
0 0 0 1 1 1 0 0
0001
-0011
-------
0001
+1101
-------
1110
A Q
1 1 1 0 1 1 0 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 3
M
0 0 1 1
A Q
1 1 1 0 1 1 0 0
1110
+0011
-------
0001
A Q
0 0 0 1 1 1 0 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 2
M
0 0 1 1
A Q
0 0 0 1 1 1 0 0
A Q
0 0 1 1 1 0 0 0
0011
-0011
-------
0011
+1101
-------
0000
A Q
0 0 0 0 1 0 0 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 2
M
0 0 1 1
A Q
0 0 0 0 1 0 0 0
A Q
0 0 0 0 1 0 0 1
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 1
M
0 0 1 1
A Q
0 0 0 0 1 0 0 1
A Q
0 0 0 1 0 0 1 0
0001
-0011
-------
0001
+1101
-------
1110
A Q
1 1 1 0 0 0 1 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 1
M
0 0 1 1
A Q
1 1 1 0 0 0 1 0
1110
+0011
-------
0001
A Q
0 0 0 1 0 0 1 0
Flowchart for Unsigned Binary Division
𝑐𝑜𝑢𝑛𝑡 = 0
M
0 0 1 1
A Q
0 0 0 1 0 0 1 0
Quotient = 0010
Remainder = 0001
Notes
• The algorithm assumes that the divisor V
and the dividend D are positive and
that 𝑉 < |𝐷| . If 𝑉 = |𝐷| , then the
quotient 𝑄 = 1 and the remainder 𝑅 = 0. If
𝑉 > |𝐷|, then 𝑄 = 0 and 𝑅 = 𝐷.
• The 𝑠𝑖𝑔𝑛(𝑅) = 𝑠𝑖𝑔𝑛(𝐷) and 𝑠𝑖𝑔𝑛(𝑄) =
𝑠𝑖𝑔𝑛(𝐷) × 𝑠𝑖𝑔𝑛(𝑉).
Real Numbers
• Numbers with fractions
• Could be done in pure binary
—1001.1010 = 23 + 20 +2-1 + 2-3 =9.625
𝟐𝟑 𝟐𝟐 𝟐𝟏 𝟐𝟎 𝟐−𝟏 𝟐−𝟐 𝟐−𝟑 𝟐−𝟒
1 0 0 1 . 1 0 1 0
±𝑆 × 𝐵 ±𝐸 E𝑥]1.10101 × 21001
• The base B is implicit and need not be stored.
• There is one bit (must equal 1) to the left of the radix
point.
• The significand only represent fraction part of number.
• The exponent is represented using biased
representation (add bias (2𝑘−1 − 1) to true exponent
value)
32-bit Floating Point Format
1.1010001 × 210100
0 10010011 10100010000000000000000
−1.1010001 × 210100
1 10010011 10100010000000000000000
1.1010001 × 2−10100
0 01101011 10100010000000000000000
00010100
11101011
Biased exponent = true exponent + (2𝑘−1 − 1) 1
Biased exponent = -00010100 + 127 ------------
Biased exponent = -00010100 + 01111111 11101100
Biased exponent = 01101011 +01111111
-------------
01101011
32-bit Floating Point Format
−1.1010001 × 2−10100
1 01101011 10100010000000000000000
00010100
11101011
Biased exponent = true exponent + (2𝑘−1 − 1) 1
Biased exponent = -00010100 + 127 ------------
Biased exponent = -00010100 + 01111111 11101100
Biased exponent = 01101011 +01111111
-------------
01101011
32-bit Floating Point Format to Decimal
1 01101011 10100010000000000000000
𝑠
Decimal Value = −1 × 1 + 𝐹𝑟𝑎𝑐𝑡𝑖𝑜𝑛 × 2𝑏𝑖𝑎𝑠𝑒𝑑𝐸𝑥𝑝𝑜𝑛𝑒𝑛𝑡−127
1
Decimal Value = −1 × 1 + (2−1 + 2−3 + 2−7 ) × 201101011−01111111
𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart
𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart
11.01 × 214
1.101 × 215
𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart
0.0101 × 214
1.01 × 212
𝒛←𝒙±𝒚
Multiplication and Division
• Check for zero
• Add/subtract exponents
• Multiply/divide significands (watch sign)
• Normalize
• Round
• All intermediate results should be in
double length storage
Floating Point Multiplication
←
Floating Point Division
← ←∞