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.

MUSIC SYNTHESIS SOFTWARE 657<br />

0199 10E6 45BO<br />

0200 10E8 85B3<br />

0201 10EA A5BO<br />

0202 10EC 1003<br />

0203 10EE 202E10<br />

0204 10F1 A5B2 SDIV1<br />

0205 10F3 1005<br />

0206 10F5 49FF<br />

0207 10F7 18<br />

0208 10F8 6901<br />

0209 10FA 206B1D SDIV2<br />

0210 10FD A5B3<br />

0211 10FF 1008<br />

0212 1101 A5B1<br />

0213 1103 49FF<br />

0214 1105 85B1<br />

0215 1107 E6B1<br />

0216 1109 60 SDIV3<br />

0217 110A<br />

o ERRORS IN PASS 2<br />

EOR ACCH COMPUTE SIGN OF QUOTIENT<br />

STA TEMP2 SAVE THE SIGN UNTIL LATER<br />

LOA ACCH TEST SIGN OF DIVIDEND<br />

BPL SOIV1 SKIP IF POSITIVE<br />

JSR DNEG TWOS COMPLEMENT DIVIDEND IF NEGATI VE<br />

LDA TEMPI TEST SIGN OF DIVISOR<br />

BPL SOIV2 JUMP IF POSITIVE<br />

EOR #$FF TWOS COMPLEMENT DIVISOR IF NEGATIVE<br />

CLC<br />

ADC #1<br />

JSR UDIV 00 THE OIVISON<br />

LOA TEMP2 TEST DESIRED SIGN OF OUOTIENT<br />

BPL SOIV3 GO RETURN IF SHOULD BE POSITIVE<br />

LOA ACCL TWOS COMPLEMENT QUOTIENT IF SHOULD BE<br />

EOR #$FF NEGATIVE<br />

STA ACCL<br />

INC ACCL<br />

RTS<br />

RETURN<br />

Fig. 18--3. Signal-processing math package for the 6502 (cont.).<br />

The shift routines do one shift at a time, again using the carry flag to<br />

transfer bits from one byte to the other. Note that when shifting right the<br />

left byte is shifted first, whereas when shifting left the tight byte is shifted<br />

first. A fair amount <strong>of</strong> fooling around is necessary to duplicate the sign bit<br />

when doing a signed shift right. A machine with decent arithmetic capability<br />

would explicitly provide a shift with sign-extend instruction. Note that<br />

the ability <strong>of</strong> the 6502 to directly modify memory greatly simplifies many<br />

operations on the pseudoaccumulator.<br />

The basic multiplication subroutine handles two 8-bit unsigned numbers<br />

and produces a 16-bit unsigned product. While most computer users<br />

know that the proper way to multiply involves shifting and adding, the<br />

number <strong>of</strong> inefficient (or just plain incorrect) multiply subroutines that have<br />

been published (Ie manufacturers are the worst <strong>of</strong>fenders) indicates a general<br />

lack <strong>of</strong> understanding in this area. Minicomputer designers <strong>of</strong> the 1960s,<br />

,-------_-------.f"L----<br />

PRODUCT<br />

SHIFT ENTIRE REGISTER AND CARRỴ.<br />

MUL flPLIER<br />

________<br />

0-1 1 ! ! ! ! ! ! i 1; 111-1)<br />

~~~~tPLIER<br />

I I BIT IS A ONE<br />

I I I I I I I<br />

MULTIPLICAND<br />

I<br />

MULTIPLIER<br />

BITS<br />

Fig. 18--4. Shift-and-add multiplication

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

Saved successfully!

Ooh no, something went wrong!