HL_Div_BC.z80 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;===============================================================
  2. HL_Div_BC:
  3. ;===============================================================
  4. ;Performs HL/BC
  5. ;Speed: 1182cc (+6cc for every 0bit in the result)
  6. ;Size: 29 bytes
  7. ;Inputs:
  8. ; DE is the numerator
  9. ; BC is the denominator
  10. ;Outputs:
  11. ; HL is the quotient
  12. ; DE is the remainder
  13. ; BC is not changed
  14. ; z flag is set
  15. ; c flag is reset
  16. ;===============================================================
  17. ex de,hl
  18. ;===============================================================
  19. DE_Div_BC:
  20. ;===============================================================
  21. ;Performs DE/BC
  22. ;Speed: 1178cc (+6cc for every 0bit in the result)
  23. ;Size: 28 bytes
  24. ;Inputs:
  25. ; HL is the numerator
  26. ; BC is the denominator
  27. ;Outputs:
  28. ; HL is the quotient
  29. ; DE is the remainder
  30. ; BC is not changed
  31. ; z flag is set
  32. ; c flag is reset
  33. ;===============================================================
  34. ld hl,0
  35. DE_Div_BC_continue:
  36. ld a,e
  37. ld e,16
  38. Div16Loop:
  39. rla
  40. rl d
  41. adc hl,hl
  42. sbc hl,bc
  43. jr nc,+_
  44. add hl,bc
  45. _:
  46. dec e
  47. jr nz,Div16Loop
  48. rla
  49. cpl
  50. ld e,a
  51. ld a,d
  52. rla
  53. cpl
  54. ld d,a
  55. ex de,hl
  56. ret