Unit 4
Unit 4
Unit 4
INDEX
UNIT-VI PPT SLIDES
Sl. No Module as per Session planner Lecture No
1. Algorithm for Addition L1
2. Algorithm for Subtraction L2
3. Algorithm for Multiplication L3
4. Algorithm for Division L4
5. Floating – point Arithmetic operations L5
6. Decimal Arithmetic unit L6
7. Decimal Arithmetic operations L7
2
ARITHMETIC OPERATIONS
4.3
Arithmetic operations on integers
4.4
Two’s complement integers
When the subtraction operation is encountered, the
computer simply changes it to an addition operation, but
makes two’s complement of the second number. In other
words:
A − B ↔ A + (B + 1)
4.5
We should remember that we add integers
column by column.
The following table shows the sum and
carry (C).
4.6
Sign-and-magnitude integers
Addition and subtraction for integers in sign-and-
magnitude representation looks very complex.
We have four different combinations of signs (two
signs, each of two values) for addition and four
different conditions for subtraction.
This means that we need to consider eight different
situations.
4.7
Addition/subtraction of integers in sign-and-magnitude format
4.8
Addition and Subtraction
Two integers A and B are stored in two’s complement format. Show how B is added to
A.
A = (00010001)2 B = (00010110)2
Solution
The operation is adding.
A is added to B and the result is stored in R.
(+17) + (+22) = (+39).
4.12
Example 4.17
Two integers A and B are stored in two’s complement format. Show how B is added to
A.
A = (00011000)2 B = (11101111)2
Solution
The operation is adding.
A is added to B and the result is stored in R.
(+24) + (17) = (+7).
4.13
Example 4.18
Two integers A and B are stored in two’s complement format. Show how B is
subtracted from A.
A = (00011000)2 B = (11101111)2
Solution
The operation is subtracting.
A is added to (B + 1) and the result is stored in R.
(+24) (17) = (+41).
4.14
Example 4.19
Two integers A and B are stored in two’s complement format. Show how B is
subtracted from A.
A = (11011101)2 B = (00010100)2
Solution
The operation is subtracting.
A is added to (B + 1) and the result is stored in R.
(−35) − (+20) = (−55).
4.15
Alternative method for Addition/subtraction of integers in sign-and-magnitude format
4.16
Example 4.20
Two integers A and B are stored in two’s complement format. Show how B is added to
A.
A = (01111111)2 B = (00000011)2
Solution
The operation is adding.
A is added to B and the result is stored in R.
Two integers A and B are stored in sign-and-magnitude format. Show how B is added
to A.
A = (0 0010001)2 B = (1 0010110)2
Solution
The operation is adding: the sign of B is not changed.
S = AS XOR BS = 1; RM = AM + (BM +1).
Since there is no overflow, we need to take the two’s complement of RM.
The sign of R is the sign of B.
(+17) + ( −22) = (−5).
4.18
Example 4.23
A = (1 1010001)2 B = (1 0010110)2
Solution
The operation is subtracting: SB = SB.
S = AS XOR BS = 1, RM = AM + (BM +1).
Since there is an overflow, the value of RM is final.
The sign of R is the sign of A.
(−81) − (−22) = (−59).
4.19
Overflow detection in two’s complement addition
• Overflow: When the signs of the addends are the
same, and the sign of the result is different
• You will never get overflow when adding 2 numbers
of opposite signs
4.20
Multiplication
• Complex
• Work out partial product for each digit
• Take care with place value (column)
• Add partial products
Multiplication Example
1011 Multiplicand (11 dec)
x 1101 Multiplier (13 dec)
1011 Partial products
0000 Note: if multiplier bit is 1 copy
1011 multiplicand (place value)
1011 otherwise zero
10001111 Product (143 dec)
00001101 Quotient
4.55
Addition and subtraction of reals
• Addition and subtraction of real numbers stored in
floating-point numbers is reduced to addition and
subtraction of two integers stored in sign-and-
magnitude (combination of sign and mantissa) after
the alignment of decimal points.
• Figure 4.8 shows a simplified version of the procedure
(there are some special cases that we have ignored).
4.56
F igure 4.8 Addition and subtraction of reals in floating-point format
4.5 7
Example 4.24
Solution
As we saw in Chapter 3, these two numbers are stored in floating-point format, as
shown below, but we need to remember that each number has a hidden 1 (which is
not stored, but assumed).
4.58
Example 4.24 (Continued)
The first few steps in the UML diagram (Figure 4.8) are not needed.
We de-normalize the numbers by adding the hidden 1s to the mantissa and
incrementing the exponent.
Now both de-normalized mantissas are 24 bits and include the hidden 1s.
They should be stored in a location that can hold all 24 bits.
Each exponent is incremented.
4.59
Example 4.24 (Continued)
4.60
Example 4.24 (Continued)
4.61
Example 4.25
Solution
These two numbers can be stored in floating-point format, as shown below:
4.62
Example 4.25 (Continued)
4.63
Example 4.25 (Continued)
4.64
Example 4.21
Two integers A and B are stored in sign-and-magnitude format (we have separated the
magnitude for clarity).Show how B is added to A.
A = (0 0010001)2 B = (0 0010110)2
Solution
The operation is adding.
A is added to B and the result is stored in R.
Bs B register
Mode
Control
AVF Complementer M
E Parallel Adder
Input
Output Carry
S
Carry
As A register Load
Sum
Flowchart of addition and subtraction of integers in sign-and-magnitude format
R=A ± B Start
Yes
Subtraction?
BS = BS
No
No Yes
As = Bs
No Yes
AM > BM R M = AM + B M
RS = AS
No Yes RM = A M – BM
AM = B M
RS = A S
RM = BM – AM Yes
RM = 0 Overflow?
RS = BS RS = 0
No
Report
Done overflow