Unit 05
Unit 05
Computer Arithmetic
Integer Representation
Integer arithmetic
Unsigned binary addition and subtraction
Unsigned binary multiplication algorithm
Booth algorithm
Unsigned binary division algorithm
Floating points representation
BCD arithmetic
BCD adder
Arithmetic pipelining
.
1. Unsigned Integers
It is an integer without sign.
Range between 0 and +veinfinity.
can contain only magnitude of the number
Example – 4
Store 258 in an 16–bit memory location.
Solution ,
Change the no in binary = 10000010
Add 7 0’s to make total no 16 bit = 0000000100000010 (memory location)
2. Signed Integers
Signed numbers contain sign flag, this representation distinguish positive and
negative numbers.
Sign-Magnitude
Example
If n = 4 then , Range = -7 to +7
If n = 5 then , Range = -15 to +15
If n = 6 then , Range = -31 to +31
If n = 3 bits , -3 to +3
If n = 5 bits , -15 to +15
2's Complement
Modern Method
Positive number represented in same way as other two methods
Negative number obtained by taking 1's Complement of positive number and adding 1.
Example -01
-6713 = 00011000 00011101
1's Comp = 11100111 11100010
Adding -----------------------------+1
Example -02
-15 = 00001111
1's Comp = 11110000
Adding ----- -------+1
Example -03
-12 = 00001100
1's Comp = 11110011
Adding -----------+1
-4 ----- 00000100
1’s com. 11111011
Adding ------------+1
11111100
+4 0 0 0 0 0 1 0 0
Word integer (16 bit) can represent numbers from -32,768 to 32,767.
-215 .. 215-1
Byte (8 bit) integer can represent numbers from -128 to 127.
-27 .. 27-1
Solution , +12
+12 -----00001100
1. Signed magnitude
2. Signed 1s complements
3. Signed 2s complements
0 0 0 0 1 1 0 0
0 0 0 0 1 1 0 0
0 0 0 0 1 1 0 0
Solution , -12
-12 -----00001100
1. Signed magnitude
2. Signed 1s complements
3. Signed 2s complements
1 0 0 0 1 1 0 0
1 1 1 1 0 0 1 1
1 1 1 1 0 1 0 0
Binary Arithmetic
In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written in the given
column and a carry of 1 over to the next column.
Example − Addition
Binary Subtraction
Subtraction and Borrow, these two words will be used very frequently for the binary subtraction.
There are four rules of binary subtraction.
Example − Subtraction
Binary Multiplication
Binary multiplication is similar to decimal multiplication. It is simpler than decimal multiplication
because only 0s and 1s are involved. There are four rules of binary multiplication.
Binary Division
Binary division is similar to decimal division. It is called as the long division procedure.
Example − Division
C A Q OPERATION N0. OF
COUNT
0 0000 1101 Initially N= 4
0 1011 1101 C,A=A+M
In the above flowchart, initially, AC and Q-1 bits are set to 0, and the SC is a sequence counter that
represents the total bits set n, which is equal to the number of bits in the multiplier. There
are M that represent the multiplicand bits, and Q represents the multiplier bits. After that, we
encountered two bits of the multiplier as Q0 and Q- 1,
The hardware implementation of the booth algorithm requires the register configuration shown in
the figure below.
We name the register as A, B and Q, AC, BR and QR respectively. Qn designates the least
significant bit of multiplier in the register QR. An extra flip-flop Qn+1is appended to QR to
facilitate a double inspection of the multiplier. Qn+1 is appended to QR to facilitate a double
inspection of the multiplier.
Example: Multiply the two numbers 7 and 3 by using the Booth's multiplication algorithm.
Ans. we need to convert 7 and 3 into binary numbers like 7 = (0111) and 3 = (0011).
M = 0111
Q=0011
Register size = 4 so SC = 4
- M = 1001 (2’S Complements of M)
The numerical example of the Booth's Multiplication Algorithm is 7 x 3 = 21 and the binary
representation of 21 is 10101. Here, we get the resultant in binary 00010101. Now we convert it
into decimal, as (000010101) 10 = 2*4 + 2*3 + 2*2 + 2*1 + 2*0 => 21.
Example: Multiply the two numbers -7 and 3 by using the Booth's multiplication
algorithm.
Ans. we need to convert 7 and 3 into binary numbers like 7 = (0111) and 3 = (0011).
M = -7 = 11001
Q=00011
Register size = 5
- M = 00111 (2’S Complements of M)
Now set 7 (in binary 0111) as multiplicand (M) and 3 (in binary 0011) as a multiplier (Q). And SC
(Sequence Count) represents the number of bits, and here we have 5 bits, so set the SC = 5. Also, it
shows the number of iteration cycles of the booth's algorithms and then cycles run SC = SC - 1 time.
Here, (1111101011)
Example: Multiply the two numbers -7 and -3 by using the Booth's multiplication
algorithm.
Examples:
Perform Division Restoring Algorithm
n M A Q Operation
Remember to restore the value of A most significant bit of A is 1. As that register Q contain
the quotient, i.e. 3 and register A contain remainder 2
The BCD-Adder is used in the computers and the calculators that perform arithmetic operation
directly in the decimal number system. The BCD-Adder accepts the binary-coded form of decimal
numbers. The Decimal-Adder requires a minimum of nine inputs and five outputs.
1. It is obvious from the table that a correction is needed when the 'Binary Sum' has an output
carry K=1.
2. The other six combinations from 10 to 15 need correction in which the bit on the Z 8 position
is 1.
3. In the Binary sum of 8 and 9, the bit on the Z 8 position is also 1. So, the second step fails, and
we need to modify it.
4. To distinguish these two numbers, we specify that the bit on the Z4 or Z2 position also needs
to be 1 with the bit of Z8
5. The condition for a correction and an output carry can be expressed by the Boolean
function:C=K+Z8.Z4+Z8.Z2
Once the circuit found the invalid BCD, the circuit adds the binary number of 6 into the invalid BCD
code to make it valid.
1. We take a 4-bit Binary-Adder, which takes addend and augend bits as an input with an input
carry 'Carry in'.
2. The Binary-Adder produces five outputs, i.e., Z8, Z4, Z2, Z1, and an output carry K.
3. With the help of the output carry K and Z8, Z4, Z2, Z1 outputs, the logical circuit is designed
to identify the Cout
4. The Z8, Z4, Z2, and Z1 outputs of the binary adder are passed into the 2 nd 4-bit binary adder
as an Augend.
5. The addend bit of the 2nd 4-bit binary adder is designed in such a way that the 1st and the
4th bit of the addend number are 0 and the 2nd and the 3rd bit are the same as Cout. When the
value of Cout is 0, the addend number will be 0000, which produce the same result as the
1st 4-bit binary number. But when the value of the Cout is 1, the addend bit will be 0110, i.e.,
6, which adds with the augent to get the valid BCD number.
Example: 1001+1000
1. First, add both the numbers using a 4-bit binary adder and pass the input carry to 0.
2. The binary adder produced the result 0001 and carried output 'K' 1.
Then, find the Cout value to identify that the produced BCD is invalid or valid using the expression
Cout=K+Z8.Z4+Z8.Z2.
The value of Cout is 1, which expresses that the produced BCD code is invalid. Then, add the output of the
1st 4-bit binary adder with 0110.
= 0001+0110
= 0111
The BCD is represented by the carry output as:
BCD=Cout Z8 Z4 Z2 Z1=1 0 1 1 1
The addition is carried out as in normal binary addition and the sum is 1 0 0 1, which is BCD
code for 9.
Types of Pipeline
It is divided into 2 categories:
1. Arithmetic Pipeline
2. Instruction Pipeline
Arithmetic Pipeline
Arithmetic Pipelines are mostly used in high-speed computers. They are used to implement floating-point
operations, multiplication of fixed-point numbers, and similar computations encountered in scientific
problems.
To understand the concepts of arithmetic pipeline in a more convenient way, let us consider an example
of a pipeline unit for floating-point addition and subtraction.
The inputs to the floating-point adder pipeline are two normalized floating-point binary numbers defined
as:
X = A * 2a = 0.9504 * 103
Y = B * 2b = 0.8200 * 102
Where A and B are two fractions that represent the mantissa and a and b are the exponents.
The combined operation of floating-point addition and subtraction is divided into four segments. Each
segment contains the corresponding suboperation to be performed in the given pipeline. The
suboperations that are shown in the four segments are:
We will discuss each suboperation in a more detailed manner later in this section.
Note: Registers are placed after each suboperation to store the intermediate results.
The exponents are compared by subtracting them to determine their difference. The larger exponent is
chosen as the exponent of the result.
The difference of the exponents, i.e., 3 - 2 = 1 determines how many times the mantissa associated with
the smaller exponent must be shifted to the right.
The mantissa associated with the smaller exponent is shifted according to the difference of exponents
determined in segment one.
X = 0.9504 * 103
Y = 0.08200 * 103
Z = X + Y = 1.0324 * 103
Z = 0.1324 * 104
Example:
Let us consider two numbers,
X=0.3214*10^3 and Y=0.4500*10^2
Explanation:
First of all the two exponents are subtracted to give 3-2=1. Thus 3 becomes the exponent of result and the
smaller exponent is shifted 1 times to the right to give
Y=0.0450*10^3
Z=0.3664*10^3
Advantages of Pipelining
Disadvantages of Pipelining
= ±mxr ±e
Only the mantissa m and the exponent e are physically represented in the register
(including their sign). A floating-point binary number is represented in a similar manner
except that is uses base 2 for the exponent. A floating-point number is said to be
normalized if the most significant digit of the mantissa is 1.
Example −Suppose number is using 32-bit format: the 1 bit sign bit, 8 bits for signed
exponent, and 23 bits for the fractional part. The leading bit 1 is not stored (as it is
always 1 for a normalized number) and is referred to as a “hidden bit”.
Then −53.5 is normalized as -53.5=(-110101.1)2=(-1.101011)x25 , which is represented
as following below,
Half Precision (16 bit): 1 sign bit, 5 bit exponent, and 10 bit mantissa
Single Precision (32 bit): 1 sign bit, 8 bit exponent, and 23 bit mantissa
Double Precision (64 bit): 1 sign bit, 11 bit exponent, and 52 bit mantissa
Quadruple Precision (128 bit): 1 sign bit, 15 bit exponent, and 112 bit mantissa