home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / dsp / c5xug.exe / INT_DIV.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-02-21  |  2.1 KB  |  64 lines

  1. ;**************************************************************
  2. ;  
  3. ;                 int_div.asm
  4. ;  
  5. ;                 staff
  6. ;  
  7. ;                 02-21-91
  8. ;  
  9. ;           (C) Texas Instruments Inc., 1992 
  10. ;  
  11. ;           Refer to the file 'license.txt' included with this 
  12. ;           this package for usage and license information. 
  13. ;  
  14. ;**************************************************************
  15. *
  16. * This routine implements integer division using the SUBC instruction.    For this
  17. * integer division routine, the absolute value of the numerator must be greater
  18. * that the absolute value of the denominator.  In addition, the calling routine
  19. * must check to verify that the divisor does not equal 0.
  20. *
  21. * The 16-bit dividend is placed in the low accumulator, and the high accumulator
  22. * is zeroed.  The divisor is in data memory.  At the completion of the last
  23. * SUBC, the quotient of the division is in the lower-order 16-bits of the
  24. * accumulator.    The remainder is in the higher-order 16-bits.
  25. *
  26. * Key C5x Instruction:
  27. * BCNDD  branch if condition true - after executing next 2-word
  28. *     instruction or two single-word instructions
  29. *
  30.  
  31.  
  32. DENOM       .set    60h
  33. NUMERA       .set    61h
  34. QUOT       .set    62h
  35. REM       .set    63h
  36. TEMSGN       .set    64h
  37. *
  38. INTDIV       LDP       #0
  39.        LT       NUMERA      ; Determine sign of quotient.
  40.        MPY       DENOM
  41.            SPH     TEMSGN
  42.        LACL    DENOM
  43.        ABS               ; Make denominator and numerator positive.
  44.        SACL    DENOM
  45.        LACL    NUMERA
  46.        ABS
  47. *
  48. * If divisor and dividend are aligned, division can start here.
  49. *
  50.        RPT       #15           ; 16 cycle division. Low accumulator contains
  51.        SUBC    DENOM       ; the quotient and high accumulator contains the
  52.                    ; remainder at the end of the loop.
  53. *
  54.        BIT       TEMSGN,0    ; Test sign of quotient.
  55.        RETCD   NTC           ; Return if sign positive, else continue.
  56.        SACL    QUOT        ; Store quotient and remainder during delayed
  57.        SACH    REM           ; branch.
  58. *
  59.        LACL    #0           ; If sign negative, negate quotient.
  60.        RETD
  61.        SUB       QUOT
  62.        SACL    QUOT
  63.  
  64.