section 7 - Index of

section 7 - Index of section 7 - Index of

11.07.2015 Views

DIV Divide Interation DIVExample: (4-Quadrant division, 24-bit signed quotient, 48-blt signed remainder)ABS A A,B;make dividend positive, copy A1 to B1EOR XO,B B,X:$O ;save rem. sign in X:$O, quo. sign in NAND #$FE,CCR ;clear carry bit C (quotient sign bit)REP #$18;form a 24-bit quotientDIV XO,A;form quotient in AO, remainder in A1TFR A,B;save quotient and remainder in B1,BOJPL SAVEQUO;go to SAVEQUO if quotient is positiveNEG 8;complement quotient if N bit setSAVEQUO TFR XO,B BO,X1;save quo. in X1, get signed divisorA8S B;get absolute value of signed divisorADD A,B;restore remainder in B1JCLR #23,X:$O,DONE ;go to DONE if remainder is positiveMOVE #$0,80 ;clear LS 24 bits of 8NEG B;complement remainder if negativeDONE .......Before ExecutionAfter ExecutionAI$00:OE66D7:F2832C AI$FF:EDCCAA:654321XO I $123456 XO I $123456X1I$000000 X1I$654321BI$00:000000:000000 BI$00:000100:654321-Explanation of Example: Prior to execution, the 56-bit A accumulator contains the 56-bit, sign-extended fractional dividend D (D=$00.OE66D7:F2832C=0.112513535894635approx.) and the 24-bit XO register contains the 24-bit, signed fractional divisor S(S=$123456=0.142222166061401). Since IDI

DIV Divide Interation DIVNote that the divide routine used in the previous example assumes that the signextended56-bit signed fractional dividend is stored in the A accumulator and that the 24-bit signed fractional divisor is stored in the XO register. This routine produces a full 24-bitsigned quotient and a 48-bit signed remainder.This routine may be greatly simplified for the case in which only positive, fractional operandsare used to produce a 24-bit positive quotient and a 48-bit positive remainder, asshown in the following example:1-Quadrant division, 24-bit unsigned quotient, 48-bit unsigned remainderAND #$FE,CCR ;clear carry bit C (quotient sign bit)REP #$18;form a 24-bit quotient and remainderDIV XO,A;form quotient in AO, remainder in A1ADD XO,A;restore remainder in A1Note that this routine assumes that the 56-bit positive, fractional, sign-extended dividendis stored in the A accumulator and that the 24-bit positive, fractional divisor is stored inthe XO register. After execution, the 24-bit positive fractional quotient is stored in the AOregister; the LS 24 bits of the 48-bit positive fractional remainder are stored in the A 1 register.There are many variations possible when choosing a suitable division routine for a givenapplication. The selection of a suitable division routine normally involves specification ofthe following items:1. the number of bits of precision in the dividend;2. the number of bits of precision N in the quotient;3. whether the value of N is fixed or is variable;4. whether the operands are unsigned or signed;5. whether or not the remainder is to be calculated.

DIV Divide Interation DIVExample: (4-Quadrant division, 24-bit signed quotient, 48-blt signed remainder)ABS A A,B;make dividend positive, copy A1 to B1EOR XO,B B,X:$O ;save rem. sign in X:$O, quo. sign in NAND #$FE,CCR ;clear carry bit C (quotient sign bit)REP #$18;form a 24-bit quotientDIV XO,A;form quotient in AO, remainder in A1TFR A,B;save quotient and remainder in B1,BOJPL SAVEQUO;go to SAVEQUO if quotient is positiveNEG 8;complement quotient if N bit setSAVEQUO TFR XO,B BO,X1;save quo. in X1, get signed divisorA8S B;get absolute value <strong>of</strong> signed divisorADD A,B;restore remainder in B1JCLR #23,X:$O,DONE ;go to DONE if remainder is positiveMOVE #$0,80 ;clear LS 24 bits <strong>of</strong> 8NEG B;complement remainder if negativeDONE .......Before ExecutionAfter ExecutionAI$00:OE66D7:F2832C AI$FF:EDCCAA:654321XO I $123456 XO I $123456X1I$000000 X1I$654321BI$00:000000:000000 BI$00:000100:654321-Explanation <strong>of</strong> Example: Prior to execution, the 56-bit A accumulator contains the 56-bit, sign-extended fractional dividend D (D=$00.OE66D7:F2832C=0.112513535894635approx.) and the 24-bit XO register contains the 24-bit, signed fractional divisor S(S=$123456=0.142222166061401). Since IDI

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

Saved successfully!

Ooh no, something went wrong!