Documente Academic
Documente Profesional
Documente Cultură
Signed Magnitude
Max: 011 ... 11.11 ... 1
Min: 111 ... 11.11 ... 1
Zero: +0 000 ... 00.00 ... 0
-0 100 ... 00.00 ... 0
2
Fixed Point Representations
6+9 -6 + 9
6 0110 9 1001
+) 9 1001 -)6 0110
15 1111 -> 01111 3 0011 -> 00011
6 + (- 9) -6 + (-9)
9 1001 6 0110
-) 6 0110 +) 9 1001
- 3 0011 -> 10011 -15 1111 -> 11111
Overflow 9 + 9 or (-9) + (-9)
9 1001
+) 9 1001
overflow (1)0010
3
Fixed Point Representations
Example
6 0 0110 -6 1 1010
+) 9 0 1001 +) 9 0 1001
15 0 1111 3 0 0011
6 0 0110 -9 1 0111
+) -9 1 0111 +) -9 1 0111
-3 1 1101 -18 (1)0 1110
9 0 1001 overflow
+) 9 0 1001
18 1 0010 2 operands have the same sign
and the result sign changes
4
Fixed Point Representations
-9 1 0110 9 0 1001
+) -9 1 0110 +) 9 0 1001
(1)0 1100 1 (1)0010
+) 1
0 1101
overflow
5
Fixed Point Representations
COMPARISON OF REPRESENTATIONS
* Hardware
* Speed of Arithmetic
* Recognition of Zero
6
Addition and Subtraction
7
Addition and Subtraction
8
Addition and Subtraction
E Output Input
Parallel Adder
Carry Carry
S
As A Register Load Sum
9
SIGNED MAGNITUDE ADDITION AND SUBTRACTION
• A and B are registers, As and Bs are FFs to store sign bit.
• The output carry is transferred to the E FF.
• AVF(Add oVerflow FF): hold overflow bit when A and B are added
• When M=0, it act as a adder
• When M = 1, it act as subtractor
• The two signs As and Bs are compared by an XOR-gate.
• If the output of the gate is:
– 0, the sign are identical
– 1, the sign are different
• For an add operation, identical signs dictate that the magnitudes be added
• For a subtract operation, difference signs dictate that the magnitudes be
added.
• The magnitudes are added with micro-operation :
EAA+B
• For an add operation, different signs dictate that the magnitudes be
subtracted.
• For a subtract operation, identical signs dictate that the magnitudes be
subtracted.
10
11
SIGNED MAGNITUDE ADDITION AND SUBTRACTION
• The carry in E after the addition constitute an overflow if E=1.
• The value of E is transfer into the AVF.
• No overflow if the numbers are subtracted so AVF is cleared to ‘0’.
• E=1 indicates that A>=B and the number in A is correct result. If A is ‘0’ then
the sign As bit must be made positive to avoid negative ‘0’.
• E=0, indicates that A<B, so it is necessary to take 2’s complement of the
value in A.
• When A<B the sign bit of the result is the complement of the original sign of
A.
• Final result is found in register A and it’s sign in A.
12
Addition and Subtraction
• The leftmost bit of binary number represents the sign bit: ‘0’ for (+ve) and
‘1’ for (-ve).
• If sign bit is 1, the entire number is represented in 2’s complement form.
• Addition:
– Sign bits treated same as the other bits of the number.
– A carry out of the sign bit position is discarded.
• Subtraction:
– Taking 2’s complement of subtrahend.
– Then adding it to the minuend.
• Overflow occurred when two numbers are added and sum occupies n+1
digits.
• An overflow can be detected by inspecting the last two carries out of the
addition.
• Cin and Cout of most significant bit are applied to the X-OR gate,
• Overflow detected when Cin X-OR Cout = 1
13
Addition and Subtraction
V Complementer and
Parallel Adder
Overflow
AC
14
SIGNED 2’S COMPLEMENT ADDITION AND SUBTRACTION
Hardware implementation algorithm
• Addition: Sum is obtained by adding the contents of registers AC and BR.
Overflow should be obtained by observing the flip-flop V.
• Subtraction:
– The subtraction operation is accomplished by adding the contents of AC to 2’s complement
of BR.
– Taking 2’s complement of BR has effect of changing a (+ve) number to (-ve), and vice versa.
– An overflow must be checked during this operation because the two numbers added could
have the same sign.
Flowchart
Subtract Add
Minuend in AC Augend in AC
Subtrahend in B Addend in B
AC AC + B’+ 1 AC AC + B
V overflow V overflow
END END 15
Ranges
Binary
No. of Unsigned Sign-magnitude 2’s complement
bits Min Max Min Max Min Max
1 0 1
2 0 3 -1 1 -2 1
3 0 7 -3 3 -4 3
4 0 15 -7 7 -8 7
5 0 31 -15 15 -16 15
6 0 63 -31 31 -32 31
Etc.
16
In General
Binary
No. of Unsigned Sign-magnitude 2’s complement
bits
Min Max Min Max Min Max
17
Multiplication
MULTIPLICATION
A = An-1An-2 ... A0
B = Bn-1Bn-2 ... B0
P=B*A
n-1
= B * ( 2i * Ai )
i=0
= An-1 * (B2n-1) + An-2 * (B2n-2) + ... + A0 * (B20)
B shifted left B shifted left B shifted left
n-1 bits n-2 bits 0 bits = A
Or
B shifted (n-1) bits to the left
18
Multiplication
MULTIPLICATION
19
Multiplication
MULTIPLICATION
Multiplication of signed magnitude data
• The multiplier and multiplicand are loaded into two registers (B and Q).
• A third register, the A register, is also needed and is initially set to 0.
• There is also a 1-bit E register, initialized to 0, which holds a potential carry
bit resulting from addition.
• Flip-flops As , Bs, and Qs are used to store the sign bit.
• A sequence counter is used to store the number of bits in multiplier.
• The operation of the multiplier is as follows:
– Control logic reads the bits of the multiplier one at a time.
– If Qn is 1, then
1. The multiplicand is added to the A register and the result is stored in the A register,
with the E bit used for overflow.
2. All of the bits of the E, A, and Q registers are shifted to the right one bit, so that the E
bit goes into An-1, A0 goes into Qn-1 and Qn is lost.
– If Qn is 0, then no addition is performed, just the shift.
– This process is repeated until SQ=0.
• Final result is obtained in EAQ registers.
20
Multiplication
Hardware
21
Algorithm Multiplication
22
Multiplication
EXAMPLE
Numerical Example
23 X 19 = 10111 X 10011
23
Multiplication
Example
001110 (14) -> p = 3, q = 1
001110 = 23+1 - 21
M * 14 = M24 - M21
Algorithm
[1] Subtract multiplicand for the first least significant 1 in a string of
1’s in the multiplier.
[2] Add multiplicand for the first 0 after the string of 1’s in the
multiplier.
[3] Partial Product does not change when the multiplier bit is identical
to the previous bit.
25
BOOTH ALGORITHM FOR SIGNED 2’S COMPLEMENT
26
EXAMPLE OF BOOTH MULTIPLIER
Example:
for n = 5
-9 X -13 =117
27
DIVISION ALGORITHM
28
Division Algorithm
Division of signed magnitude data
• Divisor is stored in register B and double length dividend is stored in
register A and Q.
• The dividend is shifted to the left and the divisor is subtracted by adding it
2’s complement value.
• If E=1, it signifies that A>=B, then
– A quotient bit 1 is inserted into Qn.
– and partial remainder is shifted to the left to repeat the process.
• If E=0, it signifies that A<B, then
– Quotient Qn remains 0 (inserted during the shift).
– The value of B is then added to restore the partial remainder in A to its previous value.
• The partial remainder is shifted to the left and the process is repeated
again until all the quotient bits are formed.
• Register EAQ is now shifted to the left with 0 inserted into the Qn and
previous value of E is lost.
29
Division Algorithm
Sign of the result
• The sign of the quotient is determined from the signs of the dividend and
the divisor.
– If the signs of the dividend and the divisor are alike the sign of quotient is (+).
– If the signs of the dividend and the divisor are unlike the sign of quotient is (-).
Divide Overflow
• When the dividend is twice as long as divisor, the condition for overflow
can be stated as follows:
• Divide overflow is detected by a divide overflow flip-flop DVF
– The divide overflow occur if the higher order bits of dividend constitute a number
greater then or equal to the divisor.
31
A / B = Q + R , A: Dividend; B: Divisor; Q: Quotient; R: Remainder
32
Divisor B = 10001, B’+ 1 = 01111
33