?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_div32
  2.  define included_div32
  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. div32_32:
  10. ;228+{0,115}+2*div32_16+mul16
  11. ;min: 1982cc
  12. ;max: 2952cc
  13. ;avg: 2560.887cc
  14. ;HLDE/(var_x+4)
  15.   ld bc,(var_x+6)
  16.   call div32_16
  17.   ld (var_b+2),de   ;top 16-bit digit
  18. ;Need to adjust the remainder
  19. ;(HL:00-DE*(var_x+4))
  20.   push hl
  21.   ld bc,(var_x+4)
  22.   call mul16
  23.  
  24.   ;DEHL
  25.   ld b,d
  26.   ld c,e
  27.   ex de,hl
  28.   pop hl
  29.   ;BCDE
  30.   xor a
  31.   sub e
  32.   ld e,a
  33.   ld a,0
  34.   sbc a,d
  35.   ld d,a
  36.   sbc hl,bc
  37.   jr nc,div32_32_final
  38. div32_320;_:
  39.   ld bc,(var_b+2)
  40.   dec bc
  41.   ld (var_b+2),bc
  42.   ld bc,(var_x+4)
  43.   ex de,hl
  44.   add hl,bc
  45.   ld bc,(var_x+6)
  46.   ex de,hl
  47.   adc hl,bc
  48.   jr nc,div32_320;-_
  49.   or a
  50. div32_32_final:
  51. ;HLDE is the new remainder
  52.   ld bc,(var_x+6)
  53.   sbc hl,bc
  54.   jr z,div32_32_finaldecvarb;+_
  55.   add hl,bc
  56.   call div32_16
  57.   ld (var_b),de   ;low 16-bits
  58.   ret
  59. div32_32_finaldecvarb;_:
  60.   dec hl
  61.   ld (var_b),hl
  62.   ret
  63.  endif
  64.