Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

Computer Organization

and Architecture

Chapter 4
Computer Arithmetic

Lecture 6
Course Content in Lectures

• Chapter 1 - Introduction

• Chapter 2 - Computer Evolution and Performance

• Chapter 3 - Computer Function and Interconnection

• Chapter 4 - Computer Arithmetic

• Chapter 5 - Instruction Sets: Characteristics and Functions

• Chapter 6 - Instruction Sets: Addressing Modes and Formats

• Chapter 7 - Processor Structure and Function

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

• Where is the binary point?


—Fixed?
– Very limited
—Moving?
– How do you show where it is?
Real Numbers
• Real numbers can be represented using scientific
notation.
±𝑆 × 𝐵 ±𝐸
Where:
𝑆 is significand, 𝐵 is base and 𝐸 is exponent
• For example
1.10101 × 21001
32-bit Floating Point Format

±𝑆 × 𝐵 ±𝐸 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

Biased exponent = true exponent + (2𝑘−1 − 1)


Biased exponent = 00010100 + 127 00010100
+01111111
Biased exponent = 00010100 + 01111111
-------------
Biased exponent = 10010011 10010011
32-bit Floating Point Format

−1.1010001 × 210100
1 10010011 10100010000000000000000

Biased exponent = true exponent + (2𝑘−1 − 1)


Biased exponent = 00010100 + 127 00010100
+01111111
Biased exponent = 00010100 + 01111111
-------------
Biased exponent = 10010011 10010011
32-bit Floating Point Format

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

Decimal Value = −1 1 × 1 + (0.6328125) × 2−20 01101011


10000001
Decimal Value = −1.6328125 × 2−20 ------------
11101100
------------
00010100
Normalization
• Floating point numbers are usually
normalized
—i.e., exponent is adjusted so that leading bit
(MSB) of significant is 1
• Since it is always 1 there is no need to
store it.
• Example]
— 0.110 × 25 ⇒ 1.10 × 24
—111.110 × 22 ⇒ 1.11110 × 24
Floating Point Ranges
• For a 32-bit number
—8 bit exponent
—+/- 2256  1.5 x 1077
• Accuracy
—The effect of changing lsb of mantissa
—23 bit mantissa 2-23  1.2 x 10-7
—About 6 decimal places
IEEE 754
• Standard for floating point storage
— 32-bit and 64-bit standards
— 8-bit and 11-bit bit exponent respectively
Floating Point Arithmetic
• A floating-point operation may produce
one of these condition:
— Exponent overflow: A positive exponent
exceeds the maximum possible exponent
value.
— Exponent underflow: A negative exponent
is less than the minimum possible
exponent value and it may be reported as 0.
— Significand underflow: In the process of
aligning significands, digits may flow
off the right end of the significand.
— Significand overflow: The addition of two
significands of the same sign may result in a
carry out of the most significant bit.
Floating Point Arithmetic
• Exponent overflow:
— Example] if the result of a multiplication operation
needs to store exponent equals to 220 in 8-bit
exponent.
• Exponent underflow:
— Example] if the result of a multiplication operation
needs to store exponent equals to −190 in 8-bit
exponent.
• Significand underflow:
— Example] if the result of an aligning process losses
some bits from one of the significant.
• Significand overflow:
— Example] if the result of an addition operation of two
significant result a carry 1.
Floating Point Arithmetic Examples
Addition and Subtraction
• The four basic phases of the Algorithm:
1. Check for zeros
2. Align significands (adjusting exponents)
3. Add or subtract significands
4. Normalize result
Phase 1: Check for Zeros
• Because addition and subtraction are
identical except for a sign change, the
process begins by changing the sign of
the subtrahend if it is a subtract
operation.
• Next, if either operand is 0, the other is
reported as the result.
— X +0=X
— 0 +X=X
— X – 0 = X + (-0) = X
— 0 – X = 0 + (-X) = -X
Phase 2: Align significands
• The next phase is to manipulate the
numbers so that the two exponents are
equal.
• Example]
— 1.00001 × 214 + 1.01 × 212
Which one to align? The small one.

= 1.00001 × 214 + 0.0101 × 214


= 1.00001 + 0.0101 × 214 = 1.01011
Phase 3: Addition
• The two significands are added together,
taking into account their signs. Because
the signs may differ, the result may be 0.
• There is also the possibility of significand
overflow by 1 digit. If so, the significand
of the result is shifted right, and the
exponent is incremented.
• An exponent overflow could occur as a
result; this would be reported, and the
operation halted.
Phase 4: Normalization
• It consists of shifting significand digits left
until the most significant bit is nonzero.
Each shift causes a decrement of the
exponent and thus could cause an
exponent underflow. Finally, the result
must be rounded off and then reported.
FP Addition & Subtraction Flowchart

𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart

1.00001 × 214 + 1.01 × 212


1.00001 × 214 + 0.0101 × 214

𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart

1.11 × 214 + 1.10 × 214

11.01 × 214
1.101 × 215

𝒛←𝒙±𝒚
FP Addition & Subtraction Flowchart

0.0011 × 214 + 0.0010 × 214

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

← ←∞

You might also like