22.09.2015 Views

of Microprocessors

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

658 MUSICAL ApPLICATIONS OF MICROPROCESSORS<br />

however, did know how to multiply and as it turns out their hardware<br />

methods are highly efficient in s<strong>of</strong>tware too.<br />

Figure 18--4 illustrates the shift and add multiplication algorithm.<br />

Two "registers" are involved; the multiplicand register which is 8 bits long,<br />

and the 16-bit pseudoaccumulator. Prior to multiplication, the multiplicand<br />

is placed in the multiplicand register, the multiplier is placed in the low<br />

order half <strong>of</strong> the pseudoaccumulator, and the high order half is cleared. A<br />

shift and add cycle consists <strong>of</strong> shifting the entire pseudoaccumulator right<br />

one bit and testing the least significant bit shifted out. If this bit is a zero,<br />

the cycle is complete. If the bit is a one, the multiplicand register is singleprecision<br />

added to the upper half<strong>of</strong> the pseudoaccumulator. This addition may<br />

overflow, so it is important to bring in the carry flag when the next shift<br />

cycle is done. A little thought will reveal that as the multiplication progresses<br />

the multiplier is "eaten away" at its right end and the product grows<br />

downward as the multiplier is shifted out. A total <strong>of</strong> 8Y2 cycles are needed to<br />

complete the operation. The half-cycle is a final shift <strong>of</strong> the pseudoaccumulator<br />

to bring in a possible overflow from the last addition and properly<br />

align the product.<br />

The above algorithm is different from many that are published in that<br />

the product is shifted right and the multiplicand stands still rather than<br />

vice versa. Efficiency improvement is due to both product and multiplier<br />

shifting being handled simultaneously and the fact that only single-precision<br />

addition <strong>of</strong> the partial products is required. If the upper part <strong>of</strong> the pseudoaccumulator<br />

is not cleared prior to multiplication, its contents wind up being<br />

added to the product. Since this may be useful and actually saves a slight<br />

amount <strong>of</strong> time, the unsigned multiplication routine provides an alternate<br />

entry point that skips clearing the product. Note that binary multiplication,<br />

even with the "free add" included, cannot overflow.<br />

Unsigned binary division, illustrated in Fig. 18-5, is precisely the<br />

reverse <strong>of</strong> multiplication. The algorithm can be described as a "shift and<br />

conditionally subtract" procedure, opposite that <strong>of</strong> multiplication. Again,<br />

DIVIDEND<br />

,<br />

SHIFT ENTIRE REGISTER LEFT<br />

REMAINDER<br />

QUOTIENT<br />

" \~-------.f1<br />

ij<br />

I I I Ii: !<br />

DIVISOR<br />

SUBTRACT IF<br />

RESULT IS<br />

NOT NEGATIVE<br />

: I<br />

OUOTIENT BITS<br />

1 FOR SUCCESSFUL<br />

SUBTRACT<br />

Fig. 18-5. Shift-and-subtract division

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!