1: / Long quotient
   2: 
   3: .globl  ldiv
   4: .globl  csv, cret
   5: 
   6: ldiv:
   7:         jsr     r5,csv
   8:         mov     10.(r5),r3
   9:         sxt     r4
  10:         bpl     1f
  11:         neg     r3
  12: 1:
  13:         cmp     r4,8.(r5)
  14:         bne     hardldiv
  15:         mov     6.(r5),r2
  16:         mov     4.(r5),r1
  17:         bge     1f
  18:         neg     r1
  19:         neg     r2
  20:         sbc     r1
  21:         com     r4
  22: 1:
  23:         mov     r4,-(sp)
  24:         clr     r0
  25:         div     r3,r0
  26:         mov     r0,r4           /high quotient
  27:         mov     r1,-(sp)        / Stash interim result.
  28:         mov     r1,r0
  29:         mov     r2,r1
  30:         div     r3,r0
  31:         bvc     1f
  32:         mov     (sp),r0         / Recover interim result.
  33:         mov     r2,r1           / (regs may be clobbered by failed div.)
  34:         sub     r3,r0           / this is the clever part
  35:         div     r3,r0
  36:         tst     r1
  37:         sxt     r1
  38:         add     r1,r0           / cannot overflow!
  39: 1:
  40:         tst     (sp)+           / Pop temp off stack.
  41:         mov     r0,r1
  42:         mov     r4,r0
  43:         tst     (sp)+
  44:         bpl     9f
  45:         neg     r0
  46:         neg     r1
  47:         sbc     r0
  48: 9:
  49:         jmp     cret
  50: 
  51: / The divisor is known to be >= 2^15 so only 16 cycles are needed.
  52: hardldiv:
  53:         clr     -(sp)
  54:         mov     6.(r5),r2
  55:         mov     4.(r5),r1
  56:         bpl     1f
  57:         com     (sp)
  58:         neg     r1
  59:         neg     r2
  60:         sbc     r1
  61: 1:
  62:         clr     r0
  63:         mov     8.(r5),r3
  64:         bge     1f
  65:         neg     r3
  66:         neg     10.(r5)
  67:         sbc     r3
  68:         com     (sp)
  69: 1:
  70:         mov     $16.,r4
  71: 1:
  72:         clc
  73:         rol     r2
  74:         rol     r1
  75:         rol     r0
  76:         cmp     r3,r0
  77:         bgt     3f
  78:         blt     2f
  79:         cmp     10.(r5),r1
  80:         blos    2f
  81: 3:
  82:         sob     r4,1b
  83:         br      1f
  84: 2:
  85:         sub     10.(r5),r1
  86:         sbc     r0
  87:         sub     r3,r0
  88:         inc     r2
  89:         sob     r4,1b
  90: 1:
  91:         mov     r2,r1
  92:         clr     r0
  93:         tst     (sp)+
  94:         beq     1f
  95:         neg     r0
  96:         neg     r1
  97:         sbc     r0
  98: 1:
  99:         jmp     cret

Defined functions

hardldiv defined in line 52; used 1 times
  • in line 14
ldiv declared in line 3; defined in line 6; used 1 times
  • in line 3
Last modified: 1982-10-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 582
Valid CSS Valid XHTML 1.0 Strict