0% found this document useful (0 votes)
92 views

Unit 3 Chapter1 Computer Arithmetic

COA
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Unit 3 Chapter1 Computer Arithmetic

COA
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Unit 3

Chapter 1
Computer
Arithmetic
Sign-magnitude

Addition and Subtraction


2’s
complement
Hardware Sign flip
implementation: flop
Overflow
FF

XOR
gates
Algorithm:

Like as: A= -2 ,
B=5
2’s complement addition and
subtraction:
Multiplication
algorithms:
A binary
example:

Partial
product
Hardware
implementation #of bit in multiplier

multiplier

Partial
product
Algorithm
:

B=11011 Q=00111
4 Q4=1,A=0,Qs
=1
EA=A+B=1011
EAQ= 0
1011

0111
Shr EAQ= 0
0101
1011

3 Q3=1
EA = 1 0000
EAQ 1 0000 1011
Shr EAQ 0 1000 0101
2 Q2=1
EA= 1 0011
EAQ 1 0011 01 01
shr EAQ 0 1001 101 0
Booth multiplication
algorithm
A= 00011 B= 00111 => A*B= A*(7)=A* (8-1)=A*8-
A*1

In 2’s compl. representation, we can use Booth alg. without


change.
Hardwar
e
Algorithm
An
example:
Array multiplier: Fast
approach
Division
A/B = q , r ; A:algorithms:
Dividend , B: Divisor, q: quotient, r:
remainder
Restoring
method:
Algorithm:

If A-B>= 0 then
DVF1
Other
methods:
• Comparison Method : Here A and B compared
prior to the subtraction operation. Then if
A>=B, B I subtracted from A. If A<B nothing is
done.
• Non-restoring: in the restoring method
when A<B  2(A-B+B)-B=2A-B,
A<B  2(A-B)+B=2A-B
Floating point
operations
• The standard format:
 IEEE 754 single
precision

• F=0 : E=0 &


f=0
•F= ±∞
F=denormalized :E=255
E=0 && f=0
:
f≠0 E=255 & f
•F=NAN: ≠0
Basic Considerations
A floating point number in computer registers consists of two parts: a mantissa ‘m’ and an
exponent ‘e’. The two parts represents a number obtained from multiplying m times a
radix r raised to the value of e;
m X re
Adding or subtracting two numbers requires first an alignment of the radix point
since the exponent parts must be made equal before adding or subtracting the
mantissas. The alignment is done by shifting one mantissa while its exponent is
adjusted until it is equal to the other exponent. Consider the sum of the following
floating-point numbers:
.5372400 X 102
+ .1580000 x 10-1
It is necessary that the two exponents be equal before the mantissas can be added.
We can either shift the first number three positions to the left, or shift the second
number three positions to the right. When the mantissas are stored in registers,
shifting to the left causes a loss of most significant digits. Shifting to the right causes
a loss of least significant digits. The second method is preferable because it only
reduces the accuracy, while the first method may cause an error. The usual
alignment procedure is to shift the mantissa that has the smaller exponent to the
right by a number of places equal to the difference between the exponents. After
this is done, the mantissas can be added:
. 5372400 X 102
+ . 0001580 X 102
.5373980 X 102
When two normalized mantissas are added, the sum may contain an
overflow digit. An overflow can be corrected easily by shifting the sum once
to the right and incrementing the exponent. When two numbers are
subtracted, the result may contain most significant zeros as shown in the
following example:
.56780 X 105
- .56430 X 105
.00350 X 105
A floating-point number that has a 0 in the most significant position of the
mantissa is said to have an underflow. To normalize a number that contains
an underflow, it is necessary to shift the mantissa to the left and decrement
the exponent until a nonzero digit appears in the first position. In the
example above, it is necessary to shift left twice to obtain .35000 X 10 3

Floating-point multiplication and division do not require an alignment of the


mantissas. The product can be formed by multiplying the two mantissas and
adding the exponents. Division is accomplished by dividing the mantissas
and subtracting the exponents.
Hardware:
Addition and
subtraction
•If BR is equal to zero, the operation is terminated, with
the value in the AC being the result. If AC is equal to zero,
we transfer the content of BR into AC and also
complement its sign if the numbers are to be subtracted.
If neither number is equal to zero, we proceed to align
the mantissas.

•The magnitude comparator attached to exponents a and


b provides three outputs that indicate their relative
magnitude. If the two exponents are equal, we go to
perform the arithmetic operation. If the exponents are
not equal, the mantissa having the smaller exponent is
shifted to the right and its exponent incremented. This
process is repeated until the two exponents are equal.
•The addition and subtraction of the two mantissas is identical to the fixed-
point addition and subtraction algorithm. The magnitude part is added or
subtracted depending on the operation and the signs of the two mantissas. If
an overflow occurs when the magnitudes are added, it is transferred into flip-
flop E. If E is equal to 1, the bit is transferred into A1 and all other bits of A are
shifted right. The exponent must be incremented to maintain the correct
number. If the magnitudes were subtracted, the result may be zero or may
have an underflow. If the mantissa is zero, the entire floating-point number in
the AC is made zero. Otherwise, the mantissa must have at least one bit that is
equal to 1. The mantissa has an underflow if the most significant bit in position
A1 is 0. In that case, the mantissa is shifted left and the exponent
decremented. The bit in A1 is checked again and the process is repeated until it
is equal to 1. When A1 = 1, the mantissa is normalized and the operation is
completed
Multiplication:
The two operands are checked to determine if they contain a zero. If either operand
is equal to zero, the product in the AC is set to zero and the operation is terminated. If
neither of the operands is equal to zero, the process continues with the exponent
addition. The exponent of the multiplier is in q and the adder is between exponents
a and b.
It is necessary to transfer the exponents from q to a, add the two exponents, and
transfer the sum into a . Since both exponents are biased by the addition of a constant,
the exponent sum will have double this bias. The correct biased exponent for the
product is obtained by subtracting the bias number from the sum.

The multiplication of the mantissas is done as in the fixed-point case with the product
residing in A and Q . Overflow cannot occur during multiplication, so there is no need
to check for it. The product may have an underflow, so the most significant bit in A is
checked. If it is a 1, the product is already normalized. If it is a 0, the mantissa in AQ is
shifted left and the exponent decremented. Note that only one normalization shift is
necessary. The multiplier and multiplicand were originally normalized and contained
fractions. The smallest normalized operand is 0.1, so the smallest possible product is
0.01. Therefore, only one leading zero may occur.

Although the low-order half of the mantissa is in Q, we do not use it for the floating-
point product. Only the value in the AC is taken as the product.
Division
:

You might also like