EC8552-LN(4)
EC8552-LN(4)
EC8552-LN(4)
ARITHMETIC
2.1 INTRODUCTION
Data is manipulated by using the arithmetic instructions in digital
computers to give solution forthe computation problems. The addition,
subtraction, multiplication and division are the four basic arithmetic operations.
Arithmetic processing unit is responsible for executing these operations
and it is located in central processing unit.
The arithmetic instructions are performed on binary or decimal data.
Fixed-point numbers are used to represent integers or fractions. These
numbers can be signed or unsigned negative numbers. A wide range of
arithmetic operations can be derived from the basic operations.
Number
Signed Magnitude Representation
+3 0011
-3 1011
0 0000
-0 1011
5 0101
-5 1101
)n two╆s complement form, a negative number is the に╆s complement of its positive number with
the subtraction of two numbers being A – B = A + ゅ に╆s complement of B ょ using much the
same process as before as basically, two╆s complement is adding な to one╆s
complement of the number.
The main difference between 12 s complement and 22 s complement is
that 12 s complement has two representations of 0 (+0): 00000000, and (-0):
11111111. In 22 s complement, there is only one representation for zero:
00000000 (0).
+0: 00000000
に╆s complement of -0:
-0: 00000000 (Signed magnitude representation)
= 0000 0000 0000 0000 0000 0000 0000 0010 (32 bits)
It is converted to a 32-bit number by making 16 copies of the value in the most significant
bit
(0) and placing that in the left-hand half of
the word. 2=0000 0000 00000010
-に=な╆s complement of に +な
1111 1111 1111 11 どな ゅな╆s complement of にょ + 1
= 1111 1111 1111 1110 (16 bits)
= 1111 1111 1111 1111 1111 1111 1111 1110 (32 bits)
To convert to 32 bit number copy the digit in the MSB of the 16 bit number for
16 times and fill the left half.
1.3 Computer Organization & Instructions
This point.
is a common method of integer representation is sign and
magnitude representation. One bit is used for denoting the sign and the
remaining bits denote the magnitude. With 7 bits reserved for the magnitude,
the largest and smallest numbers
represented are +127 and –127. Fixed-point numbers are useful for
representing fractional values, usually in base 2 or base 10, when the executing
processor has no floating point unit (FPU) or if fixed-point provides improved
performance or accuracy for the application at
hand. Most low-cost embedded microprocessors and microcontrollers do not have an FPU.
A value of a fixed-point data type is essentially an integer that is scaled
by a specific factor. The scaling factor is usually a power of 10 (for human
convenience) or a power of 2 (for computational efficiency). However, other scaling
factors may be used occasionally, e.g. a time value in hours may be represented as
a fixed-point type with a scale factor of 1/3600 to obtain values with one-second
accuracy. The maximum value of a fixed-point type is the largest value that can
be represented in the underlying integer type, multiplied by the scaling factor;
and similarly for the minimum value.
Example:
In addition, the digits are added bit by bit from right to left, with carries
passed to the next digit to the left. Subtraction operation is also done using
addition: The appropriate operand is simply negated before being added.
a) Addition b)
subtraction algorithm
Steps for addition:
Place the addend in register B and augend in AC.
Add the contents in B and AC and place the
result in AC. V register will hold the overflow
bits (if any).
Steps for subtraction:
Place the minuend in AC and subtrahend in B.
Add the contents of AC and に╆s complemented B. Place the result in
AC. V register will hold the overflow bits (if any).
The MIPS instructions for addition and subtraction are given in the following table:
2.2.2 Multiplication
Multiplication is seen as repeated addition. The first operand is called the
multiplicand and the second the multiplier. The final result is called the product.
The number of digits in the product is larger than the number in either the
multiplicand or the multiplier. The length of the multiplication of an n-bit
multiplicand and an m-bit multiplier is a product that is n + m bits long. The
steps in multiplication are:
Place a copy of the in the proper place if the multiplier
digit is a 1 Place 0 in the proper place if the digit is 0.
1. The multiplicand is subtracted from the partial product upon encountering the first
least significant な in a string of な╆s in the multiplier.
2. The multiplicand is added to the partial product upon encountering the first 0 in a
string of ど╆s in the multiplier.
3. The partial product does not change when multiplier bit is identical to
the previous multiplier bit.
The algorithm works for positive or negative multipliers in に ╆ s complement
representation. This is because a negative multiplier ends with a string of な╆s and the last
operation will be a subtraction of the appropriate weight. The two bits of the
multiplier in on and Qn+1 are inspected. If the two bits are equal to 10, it means
that the first 1 in a string of 1╅s has been encountered. This requires a subtraction of the
multiplicand from the partial
product in AC. )f the two bits are equal to どな, it means that the first ど in a string of ど╆s has
been encountered. This requires the addition of the multiplicand to the partial
product in AC. When the two bits are equal, the partial product does not
change.
1.10 Computer Organization & Instructions
Quotient=0010Remainder=0001
1.14 Computer Organization &
With this fractional number system, we can represent the fractional numbers in
the following range,
The binary point is said to be float and the numbers are called floating
point numbers. The position of binary point in floating point numbers is
variable and hence numbers must be represented in the specific manner is
referred to as floating point representation. The floating point representation
has three fields. They are:
Sign: Sign bit is the first bit of the binary representation. ╅ な ╆ implies negative number and ╅ど╆ implies
positive number.
Example: 11000001110100000000000000000001. This is
negative number since it starts with 1.
Exponent: It starts from bit next to the sign bit of the binary
representation. The exponent field is needed torepresent bothpositive and
negative exponents. To do this, a bias is added to the actual exponent in
order to get the stored exponent. For IEEE single-precision floats, this
value is 127. Thus, to express an exponent of zero, 127 is stored in the
exponent field. A stored value of 200 indicates an exponent of (200"127),
or ばぬ. The exponents of ╉なにば ゅ all ど s ょ and +なにぱ ゅ all な s) are reserved for special
numbers.
Double precision has an 11-bit exponent field, with a bias of
1023.Example: For 8 bit conversion: 8 =23-1-1=3. Bias=3.
1. 0.050 × 103
1. .5000 × 103
5.000 × 101
50.00 × 100
5000. × 10-2
Inordertomaximize thequantity of representablenumbers, floating-point
numbers are typically stored in normalized form. This basically puts the
radix point after the first non-zero digit. In normalized form, 50 is
represented as 5.000 × 101.
point:
Mantissa: Move the binary point so that there is only one bit from the left.
Adjust the exponent of 2 so that the value does not change. This is
normalizing the number. Now, consider the fractional part and
represented as 23 bits by adding zeros.
1.18 Computer Organization & Instructions
Example 2.11. Find the decimal equivalent of the floating point number:
01000001110100000000000000000000
Sign=0
Exponent:
10000011=13110
131-127=4
Exponent=
24=16
Mantissa:
Remaining 23 bits: 10100000000000000000000
=1*(1/2) + 0*(1/4) + 1*(1/8 ょ + ど*ゅな/なはょ+……… = ど.はにの Decimal number= Sign * Exponent *
Mantissa
=-1 * 16 *0.625 = -26
Example 2.11: Find the floating point equivalent of -17.
Sign=1 (-ve number)
Exponent:
Bias for 32 bit = 127 (28-1 -1 = 127) 127 + 4 = 131=100000112
Mantissa:
17 = 100012=1.0001 x 24
Fractional part=00010000000000000000000 -17 =1 10000011
000100000000000000000002
Terminologies:
Overflow: A situation in which a positive exponent becomes too large
to fit in the exponent field.
Underflow: A situation in which a negative exponent becomes too
large to fit in the exponent field.
Double precision: A floating point value represented in two 32-bit words.
2.19 Arithmetic
Single precision: A floating point value represented in a single 32-bit
Example2.15:
Express85.125insingleanddoubleprecision. 85 =
1010101
0.125 = 001
1.20 Computer Organization & Instructions
85.125 = 1010101.001
=1.010101001 x 26
Sign = 0
1. Single precision:
Biased exponent 127+6=133
133 = 10000101
Normalized mantisa = 010101001
The IEEE 754 Single precision = 0 10000101 01010100100000000000000
2. Double precision:
Biased exponent 1023+6=1029
1029 = 10000000101
Normalized mantisa =
010101001 The IEEE 754
Double precision=
0 10000000101 0101010010000000000000000000000000000000000000000000
The normalization step then shifts the sum left or right and increments or
decrements the exponent. Rounding then creates the final result, which may
require normalizing again to produce the final result.
Example 2.17: Express the following numbers in IEEE 754 format and
find their sum: 2345.125 and 0.75.Single precision format of 2345.125:
The result is +ve hence 0 is filled in the sign field. The exponent value of
2345.125 is copied in the exponent field of the result, since the 0.75 is
adjusted to the exponent of 2345.125.
Example 2.19: Multiply 1.110 x 1010 by 9.200 x 10-5. Express the product in 3 decimal
places.
1. Add the exponents
Exponent of the product=10-5=5
Multiply the significant digits 1.110 x
9.200=10.212000 Normalize the product
10.212 x 105= 1.0212 x 106
4. Round-off
1.0212 x 106= 1.021 x 106
Example 2.21: Multiply -1.110 1000 0100 0000 10101 0001 x 2-4 and 1.100 0000 0001
0000
0000 0000 x 2-2.
1. Add the exponents
Exponent of the product=-4 + -2=-6 2. Multiply the significant digits
-1.110 1000 0100 0000 10101 0001 x 1.100 0000 0001 0000 0000 0000
= 10.1011100011111011111100110010100001000000000000
3. Normalize the product 1.01011100011111011111100110010100001000000000000 x 2-
5
Arithmetic
Data movement (memory and
registers) Conditional jumps
Floating Point (FP) instructions work with a different bank of registers. Registers
are named f0 to $f31. MIPS floating-point registers are used in pairs for double
precision numbers and referred using even numbers. Single precision numbers
end with .s and double precision numbers end with .d.
FP compare single C.lt.s $f2, $f4 If(f2 < f4) Cond=1; else cond=0
(eq, ne, li, le, gt, ge)
FP compare C.lt.d $f2, $f4 If(f2 < f4) Cond=1; else cond=0
double (eq, ne, li,
le, gt, ge)
The high performance adders takes an extra input namely the transit time.
The transmit time of a logical unit is used as a time base in comparing the
operating speeds of different methods, and the number of individuallogical
units requiredis used in the comparison of costs.
The two multi-bit numbers being added together will be designated as A and B,
with individual bits being A1, A2, B1, etc. The third input will be C. Outputs will
be S (sum) R (carry), and T (transmit). The two multi bit numbers being added
together will be designated asA and B, with individual bits being A1, A2, B1,
etc. The third input will be C. Outputs will be S (sum) R (carry), and T
(transmit).
The time required to perform an addition in conventional adder is dependent on
the time required for a carry originating in the first stage to ripple through all
intervening stages
to the S or R output of the final stage. Using the transit time of a logical block as a
unit of time, this amounts to two levels to generate the carry in the first stage,
plus two levels per stage for transit through each intervening stage, plus two
levels to form the sum in the final stage, which gives a total of two times the
number of stages.
Cn=Rn-1
Cn=Dn-1 || Tn-1 Rn-2
Cn=Dn-1 || Tn-1 Dn-2 || Tn-1Tn2 Rn-3
By allowing n to have successive values starting with one and omitting all
terms containing a a resulting negative subscript, it may be seen that each
stage of the adder will
2.29 Arithmetic
require one OR stage with n inputs and n AND circuits having one through n
inputs, where N is the position number of the particular stage under
consideration.
The multiplier and the partial product will always be shifted the same
amount and at the same time.
The multiplier is shifted in relation to the decoder, and the partial product
with relation to the multiplicand.
Operation is assumed starting at the low-order end of the multiplier, which
means that shifting is to the right.
Rules:
When shifting across zeros (from low order end of multiplier), stop at the first one.
a)If this one is followed immediately by a zero, add the multiplicand, then
shift across all following zeros.
b)If this one is followed immediately by a second one, subtract the
multiplicand, then shift across all following ones.
2. When shifting across ones (from low order end of multiplier), stop at the first zero.
For this reason, if the multiplier is initially located in the part of the
register in which the product is to be developed, it should be so placed
that there will be at least two blank positions between the locations of
the low-order bit of the partial product and the high-order bit of the
multiplier.
Otherwise the low-order bit of the product will be decoded as part of the multiplier.
Multiplication Using Uniform Shifts
Multiplication which uses shifts of uniform size and permits predicting the
number of cycles that will be required from the size of the multiplier is
preferable to a method that requires varying sizes of shifts.
The most important use of this method is in the application of carry-save
adders to multiplication although it can also be used for other
applications.
Uniform shifts of two
Assume that the multiplier is divided into two-bit groups, an extra zero
being added to the high-order end, if necessary, to produce an even
number of bits.
Only one addition or subtraction will be made for each group, and, using
the position of the low-order bit in the group as a reference, this addition or
subtraction will consist of
either two times or four times the multiplicand.
These multiples may be obtained by shifting the position of entry of the
multiplicand into the adder one or two positions left from the reference
position.
The last cycle of the multiplication may require special handling.
Following any addition or subtraction, the resulting partial product will be
either correct or larger than it should be by an amount equal to one times
the multiplicand.
Thus, if the high-order pair of bits of the multiplier is 00 or 10, the
multiplicand would be multiplied by zero or two and added, which gives a
correct partial product.
If the high-order pair of bits is 01 or 11, the multiplicand is multiplied by two or four,
2.31 Arithmetic
not one or three, and added. This gives a partial product that is larger
than it should be, and the next add cycle must correct for this.
Following the addition the partial product is shifted left- two positions. This
multiplies it by four, which means that it is now larger than it should be
by four times the multiplicand.
This may be corrected during the next addition by subtracting the
difference between four and the desired multiplicand multiple.
Thus, if a pair ends in zero, the resulting partial product will be correct and
the following operation will be an addition.
If a pair ends in a one, the resulting partial product will be too large, and
the following operation will be a subtraction.
It can now be seen that the operation to be performed for any pair of bits
of the multiplier may be determined by examining that pair of bits plus the
low-order bit of
the next higher-order pair.
If the bit of the higher-order pair is a zero, an addition will result; if it is
one, a subtraction will result. If the low-order bit of a pair is considered to
have a value of one
and the high-order bit a value of two, then the multiple called for by a pair
is the numerical value of the pair if that value is even and one greater if it
is odd.
If the operation is an addition, this multiple of the multiplicand is used. If the
operation is a subtraction (the low-order bit of the next higher order pair a
one), this value is
combined with minus four to determine the correct multiple to use.
The result will be zero or negative, with a negative result meaning subtract
instead of add.
A carry-save adder has three inputs which, as far as use is concerned, may
be considered identical, and two outputs which are not identical and must
be treated in different manners.
The procedure for adding several binary numbers by using a carry-save
adder would be as follows.
Designate the inputs for the nth bit as An, Bn, and C, and the outputs for the
same bit as Sn and R, where Sn is the sum output and R. is the carry
output.
In the first cycle enter three of the input numbers into A, B, and C.
In the second cycle enter the S and R obtained from the previous cycle into
A and B and the fourth input number into C.
In this operation Sn goes into An, but Rn goes into Bn+1, where Bn+1isin the
next higher- order bit position than B.
This is continued until all of the input numbers have been entered into the adder.
Each add cycle advancesallcarriesone position, add cycles as already
described may be continued with zeros being entered into the third input
each time until the R outputs of
all stages become zero.
The alternative is to enter S and R into a carry-propagate adder and allow
time for one cycle through it.
This carry-propagate adder may be completely separate from the carry-
save unit, or it may be a combined unit with a control line for selecting
either carry-save or carry-
propagate operation.
With the appropriate sub word boundaries this technique results in parallel
processing of sub words. Since the same instruction is applied to all sub words
within the word, this is a
EC8552- Computer Architecture And
Organization
2.33 Arithmetic
form of SIMD(Single Instruction Multiple Data) processing. It is possible to apply
sub word parallelism to noncontiguous sub words of different sizes within a
word. In practical implementation is simple if sub words are same size and they
are contiguous within a word. The data parallel programs that benefit from sub
word parallelism tend to process data that are of the same size.
Example: If word size is 64bits and sub words sizes are 8,16 and 32 bits.
Hence an instruction operates on eight 8bit sub words, four 16bit sub words,
two 32bit sub words or one 64bit sub word in parallel.
Data-parallel algorithms with lower precision data map well into sub
word-parallel programs.
The support required for such sub word-parallel computations then
mirrors the needs of the data-parallel algorithms.
To exploit data parallelism, we need sub word parallel compute
primitives, which perform the same operation simultaneously on sub
words packed into a word.
These may include basic arithmetic operations like add, subtract,
multiply, divide, logical, and other compute operations.
EC8552- Computer Architecture And
Organization