Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
Division and multiplication by 2m
Division: Unsigned Integers
Let a be an n‐bit unsigned integer and let m <= n‐1
a = an‐1 2n‐1 + … + am 2m + … + a0 20
Division by 2m
a/2m = [ an‐1 2n‐1 + … + am 2m + … + a0 20] 2‐m
a/2m = [ an‐1 2n‐1‐m + … + am 20 + … + a0 2‐m]
Integer part Fractional part
Discard the fractional part
a/2m = [ an‐1 2n‐1‐m + … + am 20 ]
a/2m (after discarding the fractional part) is the same as shifting the bits of a by mbits to the right
In bit notation:
a an‐1 an‐2 … am am‐1 … a0
a/2m 0 0 … 0 0 0 an‐1 an‐2 … am
discard
pad
n‐m bitsm bits
lsd (least significant digit)
You can safely use an n‐m bit bus for a/2m . Padding to the left is needed only if a wider bus is used
ECE2560 Lesson02 Page_1
Lesson02 Page 1
Multiplication: Unsigned Integersa = an‐1 2n‐1 + … + am 2m + … + a0 20
Multiplication by 2m
a x 2m = [ an‐1 2n‐1 + … + a0 20] 2m
a x 2m = [ an‐1 2n+m‐1 + … + … + a0 2m] = [ an‐1 2n+m‐1 + … + … + a0 2m + 0 x 2m‐1+ … + 0 x 20]a x 2m is the same as shifting all the bits of a by m bits to the left
In bit notation:
a an‐1 an‐2 … am am‐1 … a
a x2m an‐1 an‐2 … am am‐1 … a0 0 0 … 0
n bits m bits
n+m bits
You can safely use an n+m bit bus for a x 2m . Padding to the left by 0's is needed if a wider bus is used
Insert 0's
ECE2560 Lesson02 Page_2
Lesson02 Page 2
Division: Signed (2's complement) Integers
For signed integers stored in 2's complement notation the procedure is exactly the same as that for unsigned integers except that we need to be carful about the sign bit. This restricts m to m <= n‐2. Also we want to make sure that after shifting right by m bits the padding on the left hand side is by 0's if the sign of a is positive and by 1's if the sign is negative. The trick is to pad with the highest significant digit of a, i.e., an‐1 which is 0 for positive integers and 1 for negative integers.
In bit notation:
a an‐1 an‐2 … am am‐1 … a0
a/2m an‐1 … an‐1 an‐1 an‐2 … am
discard
pad
n‐m bitsm bits
lsd (least significant digit)
You can safely use an n‐m bit bus for a/2m . Padding to the left is needed only if a wider bus is used
ECE2560 Lesson02 Page_3
Lesson02 Page 3
Multiplication: Signed (2's complement) Integers
Just as in the case of signed division we need to make sure that if we require padding on the left then we pad with an‐1, otherwise signed multiplication by 2m is similar to unsigned multiplication.
In bit notation:a an‐1 an‐2 … am am‐1 … a0
a 2m an‐1 an‐2 … am am‐1 … a0 0 0 … 0
n bits m bits
n+m bits
You can safely use an n+m bit bus for a x 2m . Padding to the left by an‐1 is needed if a wider bus is used
Insert 0's
ECE2560 Lesson02 Page_4
Lesson02 Page 4
MSP430G2553
Address Bus
Data Bus
MSP430G2553
ECE2560 Lesson02 Page_5
Lesson02 Page 5
ECE2560 Lesson02 Page_6
Lesson02 Page 6
ECE2560 Lesson02 Page_7
Lesson02 Page 7
ECE2560 Lesson02 Page_8
Lesson02 Page 8
ECE2560 Lesson02 Page_9
Lesson02 Page 9
ECE2560 Lesson02 Page_10
Lesson02 Page 10
ECE2560 Lesson02 Page_11
Lesson02 Page 11
ECE2560 Lesson02 Page_12
Lesson02 Page 12
ECE2560 Lesson02 Page_13
Lesson02 Page 13
ECE2560 Lesson02 Page_14
Lesson02 Page 14
ECE2560 Lesson02 Page_15
Lesson02 Page 15
ECE2560 Lesson02 Page_16
Lesson02 Page 16
ECE2560 Lesson02 Page_17
Lesson02 Page 17