Advertisement
Zeda

div_32_32_to_5bit

Dec 30th, 2019
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. div_32_32_to_5bit:
  2. inc hl
  3. inc hl
  4. inc hl
  5. inc de
  6. inc de
  7. inc de
  8.  
  9. ld a,(de)
  10. or (hl)
  11. jr nz,begin_div
  12. dec hl
  13. dec de
  14. ld a,(de)
  15. or (hl)
  16. jr nz,begin_div
  17. dec hl
  18. dec de
  19. ld a,(de)
  20. or (hl)
  21. jr nz,begin_div
  22. ;only 8 bits of each left
  23. ld c,(hl)
  24. ld a,(de)
  25. ld d,a
  26. jr C_Div_D
  27.  
  28. begin_div:
  29. ld b,(hl)
  30. dec hl
  31. ld c,(hl)
  32. ex de,hl
  33. ld d,(hl)
  34. dec hl
  35. ld e,(hl)
  36. ex de,hl
  37. ;now we need to shift these left until bit 7 is set
  38. jr div32_adjust_loop_begin
  39. div32_adjust_loop:
  40. add hl,hl
  41. sla c
  42. rl b
  43. div32_adjust_loop_begin:
  44. ld a,h
  45. or b
  46. jp p,div32_adjust_loop
  47. ld c,b
  48. ld d,h
  49.  
  50. C_Div_D:
  51. ld b,5
  52. xor a
  53.  
  54. sla c
  55. rla
  56. sla c
  57. rla
  58. sla c
  59. rla
  60.  
  61. C_Div_D_loop:
  62. sla c
  63. rla
  64. cp d
  65. jr c,+_
  66. inc c
  67. sub d
  68. _:
  69. djnz C_Div_D_loop
  70. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement