Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Binary Arithmetic - Multiplication

Similar presentations


Presentation on theme: "More Binary Arithmetic - Multiplication"— Presentation transcript:

1 More Binary Arithmetic - Multiplication
(unsigned example ) multiplying two 32-bit values gives up to a 64-bit product we go from right to left across the multiplier digits in generating partial products we could use a double-length product register, and at each step we could shift the multiplicand into the correct place for adding or not (just like the normal paper and pencil approach)

2 More Binary Arithmetic - Multiplication
(unsigned example ) e.g., bit multiplicand x bit multiplier (. is a placeholder, equal to 0) since one column is completely determined on the right at each step, we could instead arrange to shift the partial sum to the right after each add - this means we only need a 4- bit wide adder need 8-bit adder

3 More Binary Arithmetic - Multiplication
initially: carry 0 accumulator 0 mq multiplier mdr multiplicand

4 More Binary Arithmetic - Multiplication
for( i = 1; i <= n; i++ ) { /* step i */ if( mq_bit[0] == 1 ) (carry:accumulator) accumulator + mdr } shift (carry:accumulator:mq) right one place results: high bits of product in accumulator low bits of product in mq

5 e.g., bit multiplicand x bit multiplier ------ initially: C ACC MQ MDR 1111 step 1: ^ add based on lsb=1 >> shift right step 2: ^ no add based on lsb=0 >> shift right

6 -----------------------------------------
step 3: ^ add based on lsb=1 >> shift right step 4: ^ no add based on lsb=0 There are faster forms of multiplication hardware; a current processor may only require 3-5 cycles for an integer multiply

7 More Binary Arithmetic - Division
Instead of add-then-shift, division is implemented by shift- then-subtract double-length dividend divided by single-length divisor yields single-length quotient and single-length remainder we work from left to right in generating the quotient

8 More Binary Arithmetic - Division
initially: carry accumulator high bits of dividend (0s if dividend is single length) mq low bits of dividend mdr divisor

9 More Binary Arithmetic - Division
if( mdr == 0 ) { raise( DIVIDE_BY_ZERO__SIGNAL ); } if( mdr <= accumulator ){ raise( QUOTIENT_OVERFLOW_SIGNAL ); } for( i = 1; i <= n; i++ ) { /* step i */ shift (carry:accumulator:mq) left one place (carry:accumulator) (carry:accumulator) - mdr /* subtract */ if( (carry:accumulator) is negative ) { mq_bit[0] 0 (carry:accumulator) (carry:accumulator) + mdr /* restore */ } else { mq_bit[0] 1 results: quotient in mq remainder in accumulator

10 More Binary Arithmetic - Division
this is called restoring division, since the C:ACC must be restored to its previous value if the result of a subtraction is negative when the dividend is double-length, there is a special check (the value in the MDR should be greater than the value in the ACC) to make sure that the quotient won't overflow (e.g., consider / 1) when dividend is single-length, it is placed in the MQ and the ACC is set to zero

11 e.g., bit dividend / bit divisor initially: C ACC MQ MDR 1111 (step 0: ( MDR != 0 ) and ( MDR > ACC ) so no exceptions) step 1: << shift left subtract (== add ) ----- ^ set to 1 since subtract successful step 2: subtract (== add ) ----

12 ---------------------------------------------
step 3: << shift left subtract (== add ) ------ ^ set to 0 since subtract unsuccessful restoring add step 4: << shift left subtract (== add ) ^ set to 1 since subtract successful remainder quotient is in ACC is in MQ (there are faster forms of division, e.g., non-restoring)


Download ppt "More Binary Arithmetic - Multiplication"

Similar presentations


Ads by Google