Computer Architecture
Computer Architecture
CHAPTER 3
ARITHMETIC FOR COMPUTERS
3.1 Introduction
Computer words are composed of bits; thus words can be represented as binary numbers.
Addition
Digits are added bit by bit from right to left
carries passed to the next digit to the left
Subtraction
Uses addition
Appropriate operand is simply negated before added
Cout = (X Y) Cin + XY
Carry look ahead adder.
The block diagram of n-bit two’s complement adder – sub tractor with an example.
• Overflow
Occurs when the result from an operation cannot be represented with the available
hardware
• When Overflow cannot occur in Addition?
When adding operands with different signs, overflow cannot occur.
Reason Sum must be no longer than one of the operands
Assume case of 32-bit word
Example: -10+4=-6
Operands fit in 32-bits
Sum also fit in 32-bits(Reason: Sum is no larger than operand)
• When Overflow cannot occur in Subtraction?
Opposite Principle
When the signs of the operands are the same, overflow cannot occur.
Example: x - y= x + (-y)
Subtracting by negating the second operand and adding
No overflow occurs
• When overflow occurs?
Adding or subtracting two 32- bit numbers yield a result that needs 33-bits to be
fully expressed.
Lack of a 33rd bit means the overflow occurs.
Sign bit is set with the value of the result instead of the proper sign of the result.
Overflow occurs adding two positive numbers and the sum is negative (i.e a carry
out occurred in the sign bit)
In Subtraction subtracting a negative number from positive number and getting a
negative result
Subtracting a positive number from negative number and getting a positive result.(i.e
borrow occurred from the sign bit)
Saturating operations
With saturation arithmetic the result of an operation is bounded in a range between a
minimum and a maximum value. For example, with saturation arithmetic in the range [0,
255]
On overflow, result is largest representable value
E.g., clipping in audio(Saturation refers to pushing a device beyond its normal limits),
saturation in video
3.3 Multiplication
An ALU addition operation can be very time consuming when done repeatedly.
Hardware is optimized to halve the width of the adder and registers by noticing the unused
portions of registers and adders
Revised hardware
A Multiply Algorithm
Faster Multiplication
Faster multiplication Hardware
Providing one 32-bit adder for each bit of the multiplier
One input is the multiplicand ANDed with the multiplier bit
Other is the output of a prior adder
Rather than using single 32-bit adder 31 times
This unroll the loop to use 31 adders organized to minimize the delay
Faster Multiplier
Uses multiple adders
Can be pipelined
Several multiplication performed in parallel
3.4 Division
Reciprocal operation of multiply
is divide
Less Frequent
More unusual
Perform mathematical invalid
operation :dividing by 0
Relationship between the
Components
A Divide Algorithm
Using 4-bit version
710/210 or 0000 01112 by 00102
Algorithm takes n+1 steps to get quotient and remainder
Faster Division
Use many adders to speed up the multiply but cannot be done for divide
Reason: Sign of difference is to be known before the next step of the algorithm
(Subtraction is conditional on sign of remainder)
Faster dividers (e.g. SRT division) generate multiple quotient bits per step
Floating-Point Addition
• Add numbers in scientific Notation
9.99910x 101+1.61010 x 10-1
1. Align decimal points
Shift number with smaller exponent
9.99910 x 101+0.061010 x 101
2. Add significands
9.99910 x 101+0.061010 x 101
3. Normalize result & check for over/underflow
1.001510 × 102
4. Round and renormalize if necessary
1.00210 × 102
Steps
• The first step shifts the significand of the smaller number to the right until its corrected
exponent matches that of the larger number
• If sum is not normalized adjust it
• Adjust the exponent
• Whenever the exponent is increased or decreased check for overflow or
underflow(Exponent should fits in its field)
Calculating the new exponent of the product by adding the biased exponent
Multiplication of significandsfollowed by optional normalization step
Size of exponent checked for overflow and underflow
Product is rounded
If Rounding needs further normalization again check for exponent size
Set the sign bit
Set 1 if the sign of the operands were different
Set 0 if the sign of the operands were same
0.510 x -0.437510