home *** CD-ROM | disk | FTP | other *** search
- ;**************************************************************
- ;
- ; int_div.asm
- ;
- ; staff
- ;
- ; 02-21-91
- ;
- ; (C) Texas Instruments Inc., 1992
- ;
- ; Refer to the file 'license.txt' included with this
- ; this package for usage and license information.
- ;
- ;**************************************************************
- *
- * This routine implements integer division using the SUBC instruction. For this
- * integer division routine, the absolute value of the numerator must be greater
- * that the absolute value of the denominator. In addition, the calling routine
- * must check to verify that the divisor does not equal 0.
- *
- * The 16-bit dividend is placed in the low accumulator, and the high accumulator
- * is zeroed. The divisor is in data memory. At the completion of the last
- * SUBC, the quotient of the division is in the lower-order 16-bits of the
- * accumulator. The remainder is in the higher-order 16-bits.
- *
- * Key C5x Instruction:
- * BCNDD branch if condition true - after executing next 2-word
- * instruction or two single-word instructions
- *
-
-
- DENOM .set 60h
- NUMERA .set 61h
- QUOT .set 62h
- REM .set 63h
- TEMSGN .set 64h
- *
- INTDIV LDP #0
- LT NUMERA ; Determine sign of quotient.
- MPY DENOM
- SPH TEMSGN
- LACL DENOM
- ABS ; Make denominator and numerator positive.
- SACL DENOM
- LACL NUMERA
- ABS
- *
- * If divisor and dividend are aligned, division can start here.
- *
- RPT #15 ; 16 cycle division. Low accumulator contains
- SUBC DENOM ; the quotient and high accumulator contains the
- ; remainder at the end of the loop.
- *
- BIT TEMSGN,0 ; Test sign of quotient.
- RETCD NTC ; Return if sign positive, else continue.
- SACL QUOT ; Store quotient and remainder during delayed
- SACH REM ; branch.
- *
- LACL #0 ; If sign negative, negate quotient.
- RETD
- SUB QUOT
- SACL QUOT
-