?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_div64_32
  2.  define included_div64_32
  3.  include "div32_16.asm"
  4.  include "../../common/mul16.asm"
  5.  
  6. var_x=xOP2   ;output
  7. var_b=xOP2   ; 4 bytes, result gets copied to bottom anyways
  8. var_n=xOP3
  9.  
  10. div64_32:
  11. ;var_n / var_x
  12. ;HLDE is the remainder
  13. ;BCIX is the quotient
  14. ;440+2{0,96}+2*div32_16+2*mul16
  15. ;min: 2408cc
  16. ;max: 3908cc
  17. ;avg: 3356.274cc
  18.   ld hl,(var_n+6)
  19.   ld de,(var_n+4)
  20.   ld bc,(var_x+6)
  21.   call div32_16
  22.   push de
  23.  
  24. ;Need to adjust the remainder
  25.   push hl
  26.   ld bc,(var_x+4)
  27.   call mul16
  28.  
  29.   ;DEHL
  30.   ld b,d
  31.   ld c,e
  32.   ex de,hl
  33.   ld hl,(var_n+2)
  34.   or a
  35.   sbc hl,de
  36.   ex de,hl
  37.   pop hl
  38.   sbc hl,bc
  39.   jr nc,div64_32_adjust_done
  40. div64_32_adjust0;_:
  41.   pop bc
  42.   dec bc
  43.   push bc
  44.   ld bc,(var_x+4)
  45.   ex de,hl
  46.   add hl,bc
  47.   ld bc,(var_x+6)
  48.   ex de,hl
  49.   adc hl,bc
  50.   jr nc,div64_32_adjust0;-_
  51. div64_32_adjust_done:
  52. ;HLDE is the new remainder
  53.   ld bc,(var_x+6)
  54.   call div32_16
  55.   push de
  56.  
  57. ;Need to adjust the remainder
  58. ;(HL:(00-DE*(var_x+4))
  59.   push hl
  60.   ld bc,(var_x+4)
  61.   call mul16
  62.  
  63.   ;DEHL
  64.   ld b,d
  65.   ld c,e
  66.   ex de,hl
  67.   ld hl,(var_n)
  68.   or a
  69.   sbc hl,de
  70.   ex de,hl
  71.   pop hl
  72.   sbc hl,bc
  73.   jr nc,div64_32_adjustq;+_
  74.   pop bc
  75.   dec bc
  76.   push bc
  77.   ld bc,(var_x+4)
  78.   ex de,hl
  79.   add hl,bc
  80.   ld bc,(var_x+6)
  81.   ex de,hl
  82.   adc hl,bc
  83. div64_32_adjustq;_:
  84. ;HLDE is the new remainder
  85.   pop ix
  86.   pop bc
  87.   ret
  88.  endif
  89.