Number representation A number can be represented in binary in many ways. The most common number types to be represented are: • Integers, positive integers one's complement, two's complement, sign-magnitude • Decimal numbers with fixed increment fixed-point numbers • Decimal numbers with expanded range floating-point numbers William Sandqvist william@kth.se
Integers Positive Integer: -2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 =1 ⋅ 2 6 + 1 ⋅ 2 5 + 1 ⋅ 2 3 + 1 ⋅ 2 2 + 1 ⋅ 2 0 = 109 0 1 1 0 1 1 0 1 Negative Integer: -2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 = -1 ⋅ 2 7 +1 ⋅ 2 6 + 1 ⋅ 2 5 + 1 ⋅ 2 3 + 1 ⋅ 2 2 + 1 ⋅ 2 0 = -19 1 1 1 0 1 1 0 1 William Sandqvist william@kth.se
Multiplication of two positive integers 0 0 1 0 2 *11 * 1 0 1 1 0 0 1 0 Shift, add 0 0 1 0 multiplicand or 0 0 0 0 0 + 0 0 1 0 =22 0 0 1 0 1 1 0 William Sandqvist william@kth.se
Multiplication with signbit 0 0 1 0 2 * 1 0 1 1 -5 0 0 1 0 The sign has a negative weight! => Take the two-complement! 0 0 1 0 0 0 0 0 + 1 1 1 0 1 1 1 0 1 1 0 -10 William Sandqvist william@kth.se
The signbit the other way around 1 0 1 1 -5 * 0 0 1 0 2 0 0 0 0 Signextension! 1 1 1 0 1 1 (here to 7 bit’s) 0 0 0 0 + 0 0 0 0 1 1 1 0 1 1 0 -10 William Sandqvist william@kth.se
Multiplication of two negative integers 1 0 1 1 -5 * 1 0 1 1 -5 1 1 1 1 0 1 1 Signextension! 1 1 1 0 1 1 0 0 0 0 The sign has a negative weight! => Take the two-complement! + 0 1 0 1 0 0 1 1 0 0 1 +25 Answer 7-bit with sign William Sandqvist william@kth.se
Or so we make it easy for us Use only positive numbers in the multiplication Convert to positive numbers Keep track of the result's sign + ⋅ + ⇒ + + ⋅ − ⇒ − ( ) ( ) ( ) ( ) ( ) ( ) − ⋅ + ⇒ − − ⋅ − ⇒ + ( ) ( ) ( ) ( ) ( ) ( ) Two-complement for negative numbers if necessary William Sandqvist william@kth.se
A simple hardware solution … A N-1 A N-2 A 0 Sign A Sign A F correct 0 1 Sign B 0 0 1 ... Sign B 1 1 0 0 0 0 F correct =Sign A ⊕ Sign B ... HA HA HA The correction is done by inverting the bits, And 2’s complement of Product, when correction is needed. add 1 William Sandqvist william@kth.se
Multiplication (two positive integers) ⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 AND AND FA, carry AND FA, carry AND FA, carry William Sandqvist william@kth.se
Multiplication (two positive integers) ⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 AND AND FA, carry AND FA, carry AND FA, carry William Sandqvist william@kth.se
Multiplication (two positive integers) ⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 AND AND FA, carry AND FA, carry AND FA, carry William Sandqvist william@kth.se
Multiplication (two positive integers) ⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 AND AND FA, carry AND FA, carry AND FA, carry William Sandqvist william@kth.se
Multiplication (two positive integers) ⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 AND AND FA, carry AND FA, carry AND FA, carry William Sandqvist william@kth.se
⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 Multiplication (two positive integers) a a a a a a a a Shift of the 3 3 0 0 b 2 2 1 1 0 b multiplicator is 1 done by passing it a b step to the left 2 a a a a 3 0 2 1 of the grid for each level b a 3 a a a 3 2 1 0 12 FA for 4 × 4 bits q q q q q q q q 7 6 3 0 5 4 2 1 William Sandqvist william@kth.se
⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 Multiplication (two positive integers) a a a a a a a a 3 3 0 0 b 2 2 1 1 0 b T MUL ~(3*N-4)*T FA 1 b 2 a a a a 3 0 2 1 b a 3 a a a 3 2 1 0 Carry is delayed trough 8 q q q q q q q q stages! 7 6 3 0 5 4 2 1 William Sandqvist william@kth.se
Could the bit’s be added in some other order? William Sandqvist william@kth.se
Quickie question Ripple Carry-adder: a b a b a b a b C C C C 3 3 0 0 2 2 1 1 in 3 in 2 in 1 in 0 C C C C s s s s out 2 out 0 out 3 out 1 1 3 0 2 • What will happen if one confuses the lines a b C in ? a a b a b a b C b 3 0 0 2 2 1 1 in 0 3 C C C Here someone in 3 in 2 in 1 has completly confused the lines! C C C C s s s s out 0 out 2 out 3 out 1 1 0 3 2 b) Don’t care! a) Disaster! Discuss your answer with your bench neighbor! William Sandqvist william@kth.se
Quickie question a a b a b a b C b 3 0 0 2 2 1 1 in 0 3 C C C in 3 in 2 in 1 C C C C s s s s out 0 out 2 out 3 out 1 1 0 3 2 b) Don’t care! • The sum bit equals ” odd parity” of the input bits. • Carry out bit equals the ” majority value” of the inputbits. In neither case the bits order is of any significance. William Sandqvist william@kth.se
Could the bit’s be added in some other order? In this way q 2 will get the same value but with a Carry is fed different bit directly to order! the second row! William Sandqvist william@kth.se
⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 A quicker solution - Carry-Save Multiplier (BV: page 311) Figure 5.45 Multiplier carry-save array. William Sandqvist william@kth.se
⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 A quicker solution - Carry-Save Multiplier (BV: page 311) T MUL ~(2*N-2)*T FA Reduces the delay because the carry is fed directly to the next row! Carry is delayed through 6 stages! Figure 5.45 Multiplier carry-save array. William Sandqvist william@kth.se
⋅ = ( a a a a ) ( b b b b ) ( q q q q q q q q ) 3 2 1 0 3 2 1 0 7 6 5 4 3 2 1 0 A quicker solution - Carry-Save Multiplier (BV: page 311) Extra tip : A fast Carry- look ahead adder here! Figure 5.45 Multiplier carry-save array. William Sandqvist william@kth.se
William Sandqvist william@kth.se
Multiplication with the constant 2 0101*2 = 1010 (5*2=10) 1010*2 = 10100 (-6*2=-12) 01010101*2 = 010101010 (85*2=190) 10010101*2 = 100101010 (-107*2=-214) As with multiplication with 10 in our base 10: 63*10 = 630, -63*10 = -630 William Sandqvist william@kth.se
Multiplication with 2 n 0101*2 = 1010 (5*2=10) 0101*2 2 = 10100 (5*4=20) 0101*2 3 = 101000 (5*8=40) 0101*2 4 = 1010000 (5*16=80) compare multiplication with exponents of 10 in our base 10: 6*10 = 60, 6*100 = 600, 6*1000 = 6000 William Sandqvist william@kth.se
Multiplication with 2 n A multiplication with 2 n can be done by shifting all bits n steps to the left and to fill in with zeros 13 × 8 can be calculated by shifting (01011) three bits to the right Result: 01011000 corresponds to (104) 10 Note that you need more bits to represent the results! William Sandqvist william@kth.se
Barrel-shifter B 0 0 1 2 3 B 1 A 0 A 1 Multiplexor A 2 A 3 0 0 0 0 0 0 B 0 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 MUX B 1 Multiplication with (2 0 , 2 1 , 2 2 , 2 3 ) – 1, 2, 4, 8 = ⋅ ( B B ) ( S S S S S S S ) ( A A A A ) 2 1 0 6 5 4 3 2 1 0 3 2 1 0 William Sandqvist william@kth.se
Division between two positive integers (BV page 693 fig 10.21 b) 0 1 0 1 a r 11/2 = 5 = + q 1 0 1 0 1 1 b b - 1 0 0 0 1 - 0 0 Reminder = 1 0 1 1 - 1 0 1 William Sandqvist william@kth.se
a r = + A little more detail … q b b 0 1 0 1 11/2 = 5 1 0 0 1 0 1 1 - 0 0 1 0 - 1 0 0 0 1 - 0 0 Reminder = 1 0 1 1 - 1 0 1 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 1 0 1 1 r : q : b : 1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 1 0 1 1 r : q : 0 b : -1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 1 0 1 1 r : q : 0 0 b : -1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 1 0 1 1 r : q : 0 0 1 b : -1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 0 0 1 1 r : q : 0 0 1 0 b : -1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 a : 0 0 0 1 1 r : q : 0 0 1 0 1 b : -1 0 William Sandqvist william@kth.se
A little more detail … 11 1 a r = + = + 5 q b b 2 2 0 0 0 0 1 r : 1 q : 0 0 1 0 1 William Sandqvist william@kth.se
Recommend
More recommend